Advertisement
Guest User

NpcBuffer.java

a guest
Jan 6th, 2012
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package other.NpcBuffer;
  2.  
  3. import static com.l2jserver.gameserver.util.Util.formatAdena;
  4. import gnu.trove.list.array.TIntArrayList;
  5.  
  6. import java.sql.Connection;
  7. import java.sql.PreparedStatement;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.util.ArrayList;
  11. import java.util.Collections;
  12. import java.util.List;
  13.  
  14. import com.l2jserver.Config;
  15. import com.l2jserver.L2DatabaseFactory;
  16. import com.l2jserver.gameserver.datatables.ItemTable;
  17. import com.l2jserver.gameserver.datatables.SkillTable;
  18. import com.l2jserver.gameserver.instancemanager.QuestManager;
  19. import com.l2jserver.gameserver.model.L2Skill;
  20. import com.l2jserver.gameserver.model.actor.L2Npc;
  21. import com.l2jserver.gameserver.model.actor.L2Summon;
  22. import com.l2jserver.gameserver.model.actor.instance.L2CubicInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2SummonInstance;
  26. import com.l2jserver.gameserver.model.actor.stat.PcStat;
  27. import com.l2jserver.gameserver.model.actor.stat.SummonStat;
  28. import com.l2jserver.gameserver.model.actor.status.PcStatus;
  29. import com.l2jserver.gameserver.model.actor.status.SummonStatus;
  30. import com.l2jserver.gameserver.model.item.L2Item;
  31. import com.l2jserver.gameserver.model.quest.Quest;
  32. import com.l2jserver.gameserver.model.quest.QuestState;
  33. import com.l2jserver.gameserver.network.SystemMessageId;
  34. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  35. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  36. import com.l2jserver.gameserver.network.serverpackets.SetSummonRemainTime;
  37. import com.l2jserver.gameserver.network.serverpackets.SetupGauge;
  38. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  39.  
  40. public class NpcBuffer extends Quest
  41. {
  42.     private static final boolean DEBUG = false;
  43.  
  44.     private static void print(Exception e) { _log.warning(">>>"+e.toString()+"<<<"); if (DEBUG) e.printStackTrace(); }
  45.  
  46.     private static final String QUEST_LOADING_INFO = "NpcBuffer";
  47.     private static final int NPC_ID = 555;
  48.  
  49.     private static final String TITLE_NAME = "Buffer";
  50.     private static final boolean SCRIPT_RELOAD = Config.NpcBuffer_Reload;
  51.     private static final boolean SMART_WINDOW = Config.NpcBuffer_SmartWindow;
  52.     private static final boolean ENABLE_VIP_BUFFER = Config.NpcBuffer_VIP;
  53.     private static final int VIP_ACCESS_LEVEL = Config.NpcBuffer_VIP_ALV;
  54.     private static final boolean ENABLE_BUFF_SECTION = Config.NpcBuffer_EnableBuff;
  55.     private static final boolean ENABLE_SCHEME_SYSTEM = Config.NpcBuffer_EnableScheme;
  56.     private static final boolean ENABLE_HEAL = Config.NpcBuffer_EnableHeal;
  57.     private static final boolean ENABLE_BUFFS = Config.NpcBuffer_EnableBuffs;
  58.     private static final boolean ENABLE_RESIST = Config.NpcBuffer_EnableResist;
  59.     private static final boolean ENABLE_SONGS = Config.NpcBuffer_EnableSong;
  60.     private static final boolean ENABLE_DANCES = Config.NpcBuffer_EnableDance;
  61.     private static final boolean ENABLE_CHANTS = Config.NpcBuffer_EnableChant;
  62.     private static final boolean ENABLE_OTHERS = Config.NpcBuffer_EnableOther;
  63.     private static final boolean ENABLE_SPECIAL = Config.NpcBuffer_EnableSpecial;
  64.     private static final boolean ENABLE_CUBIC = Config.NpcBuffer_EnableCubic;
  65.     private static final boolean ENABLE_BUFF_REMOVE = Config.NpcBuffer_EnableCancel;
  66.     private static final boolean ENABLE_BUFF_SET = Config.NpcBuffer_EnableBuffSet;
  67.     private static final boolean BUFF_WITH_KARMA = Config.NpcBuffer_EnableBuffPK;
  68.     private static final boolean FREE_BUFFS = Config.NpcBuffer_EnableFreeBuffs;
  69.     private static final boolean TIME_OUT = Config.NpcBuffer_EnableTimeOut;
  70.     private static final int TIME_OUT_TIME = Config.NpcBuffer_TimeOutTime;
  71.     private static final int MIN_LEVEL = Config.NpcBuffer_MinLevel;
  72.     private static final int BUFF_REMOVE_PRICE = Config.NpcBuffer_PriceCancel;
  73.     private static final int HEAL_PRICE = Config.NpcBuffer_PriceHeal;
  74.     private static final int BUFF_PRICE = Config.NpcBuffer_PriceBuffs;
  75.     private static final int RESIST_PRICE = Config.NpcBuffer_PriceResist;
  76.     private static final int SONG_PRICE = Config.NpcBuffer_PriceSong;
  77.     private static final int DANCE_PRICE = Config.NpcBuffer_PriceDance;
  78.     private static final int CHANT_PRICE = Config.NpcBuffer_PriceChant;
  79.     private static final int OTHERS_PRICE = Config.NpcBuffer_PriceOther;
  80.     private static final int SPECIAL_PRICE = Config.NpcBuffer_PriceSpecial;
  81.     private static final int CUBIC_PRICE = Config.NpcBuffer_PriceCubic;
  82.     private static final int BUFF_SET_PRICE = Config.NpcBuffer_PriceSet;
  83.     private static final int SCHEME_BUFF_PRICE = Config.NpcBuffer_PriceScheme;
  84.     private static final int SCHEMES_PER_PLAYER = Config.NpcBuffer_MaxScheme;
  85.     private static final int CONSUMABLE_ID = Config.NpcBuffer_consumableID;
  86.     private static final int MAX_SCHEME_BUFFS = Config.BUFFS_MAX_AMOUNT;
  87.     private static final int MAX_SCHEME_DANCES = Config.DANCES_MAX_AMOUNT;
  88.  
  89.     private static final String SET_FIGHTER = "Fighter";
  90.     private static final String SET_MAGE = "Mage";
  91.     private static final String SET_ALL = "All";
  92.     private static final String SET_NONE = "None";
  93.  
  94.    
  95.     private String rebuildMainHtml(QuestState st)
  96.     {
  97.         String MAIN_HTML_MESSAGE = "<html><head><title>" + TITLE_NAME + "</title></head><body><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32>";
  98.         String MESSAGE = "";
  99.         int td=0;
  100.         String[] TRS = {"<tr><td height=25>", "</td>", "<td height=25>", "</td></tr>"};
  101.  
  102.         final String bottonA, bottonB, bottonC;
  103.         if (st.getInt("Pet-On-Off") == 1) {
  104.             bottonA = "Auto Buff Pet"; bottonB = "Heal My Pet"; bottonC = "Remove Pet Buffs";
  105.             MAIN_HTML_MESSAGE += "<button value=\"Pet Options\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " buffpet 0 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  106.         }
  107.         else {
  108.             bottonA = "Auto Buff"; bottonB = "Heal Me"; bottonC = "Remove Buffs";
  109.             MAIN_HTML_MESSAGE += "<button value=\"Char Options\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " buffpet 1 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  110.         }
  111.  
  112.         if (ENABLE_BUFF_SECTION) {
  113.             if (ENABLE_BUFFS) {
  114.                 if (td>2) td=0;
  115.                 MESSAGE += TRS[td] + "<button value=\"Buffs\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect view_buffs 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">" + TRS[td + 1];
  116.                 td+=2;
  117.             }
  118.             if (ENABLE_RESIST) {
  119.                 if (td>2) td=0;
  120.                 MESSAGE += TRS[td] + "<button value=\"Resist\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect view_resists 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">" + TRS[td + 1];
  121.                 td+=2;
  122.             }
  123.             if (ENABLE_SONGS) {
  124.                 if (td>2) td=0;
  125.                 MESSAGE += TRS[td] + "<button value=\"Songs\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect view_songs 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">" + TRS[td + 1];
  126.                 td+=2;
  127.             }
  128.             if (ENABLE_DANCES) {
  129.                 if (td>2) td=0;
  130.                 MESSAGE += TRS[td] + "<button value=\"Dances\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect view_dances 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">" + TRS[td + 1];
  131.                 td+=2;
  132.             }
  133.             if (ENABLE_CHANTS) {
  134.                 if (td>2) td=0;
  135.                 MESSAGE += TRS[td] + "<button value=\"Chants\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect view_chants 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">" + TRS[td + 1];
  136.                 td+=2;
  137.             }
  138.             if (ENABLE_SPECIAL) {
  139.                 if (td>2) td=0;
  140.                 MESSAGE += TRS[td] + "<button value=\"Special\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect view_special 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">" + TRS[td + 1];
  141.                 td+=2;
  142.             }
  143.             if (ENABLE_OTHERS) {
  144.                 if (td>2) td=0;
  145.                 MESSAGE += TRS[td] + "<button value=\"Others\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect view_others 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">" + TRS[td + 1];
  146.                 td+=2;
  147.             }
  148.         }
  149.         if (ENABLE_CUBIC) {
  150.             if (td>2) td=0;
  151.             MESSAGE += TRS[td] + "<button value=\"Cubics\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect view_cubic 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">" + TRS[td + 1];
  152.             td+=2;
  153.         }
  154.         if (MESSAGE.length() > 0) {
  155.             MAIN_HTML_MESSAGE += "<BR1><table width=100% border=0 cellspacing=0 cellpadding=1 bgcolor=444444><tr>"
  156.                               +  "<td><font color=00FFFF>Buffs:</font></td><td align=right>...</td></tr></table>"
  157.                               +  "<BR1><table cellspacing=0 cellpadding=0>" + MESSAGE + "</table>";
  158.             MESSAGE = "";
  159.             td = 0;
  160.         }
  161.  
  162.         if (ENABLE_BUFF_SET) {
  163.             if (td>2) td=0;
  164.             MESSAGE += TRS[td] + "<button value=\"" + bottonA + "\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " castBuffSet 0 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">" + TRS[td + 1];
  165.             td+=2;
  166.         }
  167.         if (ENABLE_HEAL) {
  168.             if (td>2) td=0;
  169.             MESSAGE += TRS[td] + "<button value=\"" + bottonB + "\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " heal 0 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">" + TRS[td + 1];
  170.             td+=2;
  171.         }
  172.         if (ENABLE_BUFF_REMOVE) {
  173.             if (td>2) td=0;
  174.             MESSAGE += TRS[td] + "<button value=\"" + bottonC + "\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " removeBuffs 0 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">" + TRS[td + 1];
  175.             td+=2;
  176.         }
  177.         if (MESSAGE.length() > 0) {
  178.             MAIN_HTML_MESSAGE += "<BR1><table width=100% border=0 cellspacing=0 cellpadding=1 bgcolor=444444><tr>"
  179.                               +  "<td><font color=00FFFF>Preset:</font></td><td align=right><font color=LEVEL>" + formatAdena(BUFF_SET_PRICE) + "</font> adena</td></tr></table>"
  180.                               +  "<BR1><table cellspacing=0 cellpadding=0>" + MESSAGE + "</table>";
  181.             MESSAGE = "";
  182.             td = 0;
  183.         }
  184.  
  185.         if (ENABLE_SCHEME_SYSTEM)
  186.             MAIN_HTML_MESSAGE += generateScheme(st);
  187.  
  188.         if (st.getPlayer().isGM())
  189.             MAIN_HTML_MESSAGE += "<br><button value=\"GM Manage Buffs\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect manage_buffs 0 0\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  190.         MAIN_HTML_MESSAGE += "<br><font color=303030>" + TITLE_NAME + "</font>"
  191.                           +  "</center></body></html>";
  192.         return MAIN_HTML_MESSAGE;
  193.     }
  194.  
  195.     private String generateScheme(QuestState st)
  196.     {
  197.         List<String> schemeName = new ArrayList<>();
  198.         List<String> schemeId = new ArrayList<>();
  199.         String HTML = "";
  200.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  201.         {
  202.             PreparedStatement rss = con.prepareStatement("SELECT * FROM npcbuffer_scheme_list WHERE player_id=?");
  203.             rss.setInt(1, st.getPlayer().getObjectId());
  204.             ResultSet action = rss.executeQuery();
  205.             while (action.next()) {
  206.                 schemeName.add(action.getString("scheme_name"));
  207.                 schemeId.add(action.getString("id"));
  208.             }
  209.         }
  210.         catch (SQLException e) { print(e); }
  211.         HTML += "<BR1><table width=100% border=0 cellspacing=0 cellpadding=1 bgcolor=444444><tr>"
  212.              +  "<td><font color=00FFFF>Scheme:</font></td><td align=right><font color=LEVEL>" + formatAdena(SCHEME_BUFF_PRICE) + "</font> adena</TD></TR></table>"
  213.              +  "<BR1><table cellspacing=0 cellpadding=0>";
  214.         if (schemeName.size() > 0) {
  215.             String MESSAGE = "";
  216.             int td = 0;
  217.             String[] TRS = {"<tr><td>", "</td>", "<td>", "</td></tr>"};
  218.             for (int i = 0; i < schemeName.size(); ++i) {
  219.                 if (td>2) td=0;
  220.                 MESSAGE += TRS[td] + "<button value=\"" + schemeName.get(i) + "\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " cast " + schemeId.get(i) + " x x\" width=130 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">" + TRS[td + 1];
  221.                 td+=2;
  222.             }
  223.             if (MESSAGE.length() > 0)
  224.                 HTML += "<table>" + MESSAGE + "</table>";
  225.         }
  226.         if (schemeName.size() < SCHEMES_PER_PLAYER)
  227.             HTML += "<BR1><table><tr><td><button value=\"Create\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " create_1 x x x\" width=85 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>";
  228.         else
  229.             HTML += "<BR1><table width=100><tr>";
  230.         if (schemeName.size() > 0)
  231.             HTML += "<td><button value=\"Edit\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " edit_1 x x x\" width=85 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>"
  232.                  +  "<td><button value=\"Delete\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " delete_1 x x x\" width=85 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr></table>";
  233.         else
  234.             HTML += "</tr></table>";
  235.         return HTML;
  236.     }
  237.  
  238.     private String reloadPanel(QuestState st)
  239.     {
  240.         return "<html><head><title>" + TITLE_NAME + "</title></head><body><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>"
  241.              +  "<font color=303030>" + TITLE_NAME + "</font><br>"
  242.              +  "<img src=\"L2UI.SquareGray\" width=250 height=1><br>"
  243.              +  "<table width=260 border=0 bgcolor=444444>"
  244.              +  "<tr><td><br></td></tr>"
  245.              +  "<tr><td align=center><font color=FFFFFF>This option can be seen by GMs only and it<br1>allow to update any changes made in the<br1>script. You can disable this option in<br1>the settings section within the Script.<br><font color=LEVEL>Do you want to update the SCRIPT?</font></font></td></tr>"
  246.              +  "<tr><td></td></tr></table><br>"
  247.              +  "<img src=\"L2UI.SquareGray\" width=250 height=1><br><br>"
  248.              +  "<button value=\"Yes\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " reloadscript 1 0 0\" width=50 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  249.              +  "<button value=\"No\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " reloadscript 0 0 0\" width=50 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  250.              +  "</center></body></html>";
  251.     }
  252.  
  253.     private String getItemNameHtml(QuestState st, int itemval)
  254.     {
  255.         return "&#" + itemval + ";";
  256.       //return ItemTable.getInstance().getTemplate(itemval) != null ? "&#" + itemval + ";" : "No Name";
  257.     }
  258.  
  259.     @SuppressWarnings("unused")
  260.     private String getItemName(QuestState st, int itemval)
  261.     {
  262.         L2Item t = ItemTable.getInstance().getTemplate(itemval);
  263.         return t != null ? t.getName() : "No Name";
  264.     }
  265.  
  266.     private int getBuffCount(String scheme)
  267.     {
  268.         int count = 0;
  269.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  270.         {
  271.             PreparedStatement rss = con.prepareStatement("SELECT buff_class FROM npcbuffer_scheme_contents WHERE scheme_id=?");
  272.             rss.setString(1, scheme);
  273.             ResultSet action = rss.executeQuery();
  274.             while (action.next())
  275.                 ++count;
  276.         }
  277.       //catch (SQLException e) { count = 0; } //TODO:
  278.         catch (SQLException e) { print(e); }
  279.         return count;
  280.     }
  281.  
  282.     private String getBuffType(int id)
  283.     {
  284.         String val = "none";
  285.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  286.         {
  287.             PreparedStatement act = con.prepareStatement("SELECT buffType FROM npcbuffer_buff_list WHERE buffId=? LIMIT 1");
  288.             act.setInt(1, id);
  289.             ResultSet rs = act.executeQuery();
  290.             if (rs.next())
  291.                 val = rs.getString("buffType");
  292.         }
  293.         catch (SQLException e) { print(e); }
  294.         return val;
  295.     }
  296.  
  297.     private boolean isEnabled(int id, int level)
  298.     {
  299.         boolean val = false;
  300.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  301.         {
  302.             PreparedStatement act = con.prepareStatement("SELECT canUse FROM npcbuffer_buff_list WHERE buffId=? AND buffLevel=? LIMIT 1");
  303.             act.setInt(1, id);
  304.             act.setInt(2, level);
  305.             ResultSet rs = act.executeQuery();
  306.             if (rs.next())
  307.                 if ("1".equals(rs.getString("canUse"))) val = true;
  308.         }
  309.         catch (SQLException e) { print(e); }
  310.         return val;
  311.     }
  312.  
  313.     private boolean isUsed(String scheme, int id, int level)
  314.     {
  315.         boolean used = false;
  316.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  317.         {
  318.             PreparedStatement rss = con.prepareStatement("SELECT id FROM npcbuffer_scheme_contents WHERE scheme_id=? AND skill_id=? AND skill_level=? LIMIT 1");
  319.             rss.setString(1, scheme);
  320.             rss.setInt(2, id);
  321.             rss.setInt(3, level);
  322.             ResultSet action = rss.executeQuery();
  323.             if (action.next())
  324.                 used = true;
  325.         }
  326.       //catch (SQLException e) { count = 0; } //TODO:
  327.         catch (SQLException e) { print(e); }
  328.         return used;
  329.     }
  330.  
  331.     private int getClassBuff(String id)
  332.     {
  333.         int val = 0;
  334.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  335.         {
  336.             PreparedStatement getTipo = con.prepareStatement("SELECT buff_class FROM npcbuffer_buff_list WHERE buffId=?");
  337.             getTipo.setString(1, id);
  338.             ResultSet gt = getTipo.executeQuery();
  339.             if (gt.next())
  340.                 val = gt.getInt("buff_class");
  341.         }
  342.         catch (SQLException e) { print(e); }
  343.         return val;
  344.     }
  345.  
  346.     private String showText(QuestState st, String type, String text, boolean buttonEnabled, String buttonName, String location)
  347.     {
  348.         String MESSAGE = "<html><head><title>" + TITLE_NAME + "</title></head><body><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>";
  349.         MESSAGE += "<font color=LEVEL>" + type + "</font><br>" + text + "<br>";
  350.         if (buttonEnabled)
  351.             MESSAGE += "<button value=\"" + buttonName + "\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect " + location + " 0 0\" width=100 height=22 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  352.         MESSAGE += "<font color=303030>" + TITLE_NAME + "</font></center></body></html>";
  353.         st.playSound("ItemSound3.sys_shortage");
  354.         return MESSAGE;
  355.     }
  356.  
  357.     private String reloadConfig(QuestState st)
  358.     {
  359.         try {
  360.             if (QuestManager.getInstance().reload(QUEST_LOADING_INFO)) st.getPlayer().sendMessage("The script and settings have been reloaded successfully.");
  361.             else st.getPlayer().sendMessage("Script Reloaded Failed. you edited something wrong! :P, fix it and restart the server");
  362.         }
  363.         catch (Exception e) {
  364.             st.getPlayer().sendMessage("Script Reloaded Failed. you edited something wrong! :P, fix it and restart the server");
  365.             print(e);
  366.         }
  367.         return rebuildMainHtml(st);
  368.     }
  369.  
  370.     private NpcBuffer(int id, String name, String descr)
  371.     {
  372.         super(id, name, descr);
  373.         addStartNpc(NPC_ID);
  374.         addFirstTalkId(NPC_ID);
  375.         addTalkId(NPC_ID);
  376.     }
  377.  
  378.     private boolean isPetBuff(QuestState st)
  379.     {
  380.         return st.getInt("Pet-On-Off") != 0;
  381.     }
  382.  
  383.     private String createScheme()
  384.     {
  385.         return "<html><head><title>" + TITLE_NAME + "</title></head><body><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br><br>You MUST seprerate new words with a dot (.)<br><br>Scheme name: <edit var=\"name\" width=100><br><br>"
  386.              +  "<button value=\"Create Scheme\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " create $name no_name x x\" width=200 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  387.              +  "<br><button value=\"Back\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect main 0 0\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  388.              +  "<br><font color=303030>" + TITLE_NAME + "</font></center></body></html>";
  389.     }
  390.  
  391.     private String deleteScheme(L2PcInstance player)
  392.     {
  393.         String HTML = "<html><head><title>" + TITLE_NAME + "</title></head><body><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>Available schemes:<br><br>";
  394.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  395.         {
  396.             PreparedStatement rss = con.prepareStatement("SELECT * FROM npcbuffer_scheme_list WHERE player_id=?");
  397.             rss.setInt(1, player.getObjectId());
  398.             ResultSet action = rss.executeQuery();
  399.             while (action.next())
  400.                 HTML += "<button value=\"" + action.getString("scheme_name") + "\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " delete_c " + action.getString("id") + " " + action.getString("scheme_name") + " x\" width=200 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  401.         }
  402.       //catch (SQLException e) { print "Query error!"; } //TODO:
  403.         catch (SQLException e) { print(e); }
  404.         HTML += "<br><button value=\"Back\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect main 0 0\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  405.              +  "<br><font color=303030>" + TITLE_NAME + "</font></center></body></html>";
  406.         return HTML;
  407.     }
  408.  
  409.     private String editScheme(L2PcInstance player)
  410.     {
  411.         String HTML = "<html><head><title>" + TITLE_NAME + "</title></head><body><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>Select a scheme that you would like to manage:<br><br>";
  412.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  413.         {
  414.             PreparedStatement rss = con.prepareStatement("SELECT * FROM npcbuffer_scheme_list WHERE player_id=?");
  415.             rss.setInt(1, player.getObjectId());
  416.             ResultSet action = rss.executeQuery();
  417.             while (action.next()) {
  418.                 String name = action.getString("scheme_name");
  419.                 String id = action.getString("id");
  420.                 HTML += "<button value=\"" + name + "\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " manage_scheme_select " + id + " x x\" width=200 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  421.             }
  422.         }
  423.       //catch (SQLException e) { print "Query error!"; } //TODO:
  424.         catch (SQLException e) { print(e); }
  425.         HTML += "<br><button value=\"Back\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect main 0 0\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  426.              +  "<br><font color=303030>" + TITLE_NAME + "</font></center></body></html>";
  427.         return HTML;
  428.     }
  429.  
  430.     private String getOptionList(String scheme)
  431.     {
  432.         int bcount = getBuffCount(scheme);
  433.         String HTML = "<html><head><title>" + TITLE_NAME + "</title></head><body><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>There are <font color=LEVEL>" + bcount + "</font> buffs in current scheme!<br><br>";
  434.         if (bcount < MAX_SCHEME_BUFFS + MAX_SCHEME_DANCES)
  435.             HTML += "<button value=\"Add buffs\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " manage_scheme_1 " + scheme + " 1 x\" width=200 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  436.         if (bcount > 0)
  437.             HTML += "<button value=\"Remove buffs\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " manage_scheme_2 " + scheme + " 1 x\" width=200 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  438.         HTML += "<br><button value=\"Back\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " edit_1 0 0 0\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  439.              +  "<button value=\"Home\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect main 0 0\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  440.              +  "<br><font color=303030>" + TITLE_NAME + "</font></center></body></html>";
  441.         return HTML;
  442.     }
  443.  
  444.     private String buildHtml(String buffType)
  445.     {
  446.         String HTML_MESSAGE = "<html><head><title>" + TITLE_NAME + "</title></head><body><center><br>";
  447.  
  448.         List<String> availableBuffs = new ArrayList<>();
  449.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  450.         {
  451.             PreparedStatement getList = con.prepareStatement("SELECT buffId,buffLevel FROM npcbuffer_buff_list WHERE buffType=\"" + buffType + "\" AND canUse=1  ORDER BY Buff_Class ASC, id");
  452.             ResultSet rs = getList.executeQuery();
  453.             while (rs.next()) {
  454.           //try :
  455.                 int bId = rs.getInt("buffId");
  456.                 int bLevel = rs.getInt("buffLevel");
  457.                 String bName = SkillTable.getInstance().getInfo(bId, bLevel).getName();
  458.                 bName = bName.replace(" ", "+");
  459.                 availableBuffs.add(bName + "_" + bId + "_" + bLevel);
  460.           //except: HTML_MESSAGE += "Error loading buff list...<br>"
  461.             }
  462.         }
  463.         catch (SQLException e) { print(e); }
  464.  
  465.         if (availableBuffs.size() == 0) {
  466.             HTML_MESSAGE += "No buffs are available at this moment!";
  467.         }
  468.         else {
  469.             if (FREE_BUFFS)
  470.                 HTML_MESSAGE += "All buffs are for <font color=LEVEL>free</font>!";
  471.             else {
  472.                 int price = 0;
  473.                 switch (buffType) {
  474.                     case "buff": price = BUFF_PRICE; break;
  475.                     case "resist": price = RESIST_PRICE; break;
  476.                     case "song": price = SONG_PRICE; break;
  477.                     case "dance": price = DANCE_PRICE; break;
  478.                     case "chant": price = CHANT_PRICE; break;
  479.                     case "others": price = OTHERS_PRICE; break;
  480.                     case "special": price = SPECIAL_PRICE; break;
  481.                     case "cubic": price = CUBIC_PRICE; break;
  482.                     default: if (DEBUG) throw new RuntimeException();
  483.                 }
  484.                 HTML_MESSAGE += "All special buffs cost <font color=LEVEL>" + formatAdena(price) + "</font> adena!";
  485.             }
  486.  
  487.             HTML_MESSAGE += "<BR1><table>";
  488.             for (String buff : availableBuffs) {
  489.                 buff = buff.replace("_", " ");
  490.                 String[] buffSplit = buff.split(" ");
  491.                 String name = buffSplit[0];
  492.                 int id = Integer.parseInt(buffSplit[1]);
  493.                 int level = Integer.parseInt(buffSplit[2]);
  494.                 name = name.replace("+", " ");
  495.                 HTML_MESSAGE += "<tr><td>" + getSkillIconHtml(id, level) + "</td><td><button value=\"" + name + "\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " giveBuffs " + id + " " + level + " " + buffType + "\" width=190 height=32 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>";
  496.             }
  497.             HTML_MESSAGE += "</table>";
  498.         }
  499.  
  500.         HTML_MESSAGE += "<br><button value=\"Back\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect main 0 0\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  501.                      +  "<br><font color=303030>" + TITLE_NAME + "</font></center></body></html>";
  502.         return HTML_MESSAGE;
  503.     }
  504.  
  505.     private String generateQuery(int case1, int case2)
  506.     {
  507.         StringBuilder qry = new StringBuilder();
  508.         if (ENABLE_BUFFS) if (case1 < MAX_SCHEME_BUFFS) qry.append(",\"buff\"");
  509.         if (ENABLE_RESIST) if (case1 < MAX_SCHEME_BUFFS) qry.append(",\"resist\"");
  510.         if (ENABLE_SONGS) if (case2 < MAX_SCHEME_DANCES) qry.append(",\"song\"");
  511.         if (ENABLE_DANCES) if (case2 < MAX_SCHEME_DANCES) qry.append(",\"dance\"");
  512.         if (ENABLE_CHANTS) if (case1 < MAX_SCHEME_BUFFS) qry.append(",\"chant\"");
  513.         if (ENABLE_OTHERS) if (case1 < MAX_SCHEME_BUFFS) qry.append(",\"others\"");
  514.         if (ENABLE_SPECIAL) if (case1 < MAX_SCHEME_BUFFS) qry.append(",\"special\"");
  515.         if (qry.length() > 0) qry.deleteCharAt(0);
  516.         return qry.toString();
  517.     }
  518.     /*********************************************************************/
  519.     private String viewAllSchemeBuffs$getBuffCount(String scheme)
  520.     {
  521.         int count = 0; int D_S_Count = 0; int B_Count = 0;
  522.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  523.         {
  524.             PreparedStatement rss = con.prepareStatement("SELECT buff_class FROM npcbuffer_scheme_contents WHERE scheme_id=?");
  525.             rss.setString(1, scheme);
  526.             ResultSet action = rss.executeQuery();
  527.             while (action.next()) {
  528.                 ++count;
  529.                 int val = action.getInt("buff_class");
  530.                 if (val == 1 || val == 2) ++D_S_Count;
  531.                 else ++B_Count;
  532.             }
  533.         }
  534.       //catch (SQLException e) { count = 0; D_S_Count = 0 ; B_Count = 0; } //TODO:
  535.         catch (SQLException e) { print(e); }
  536.         String res = count + " " + B_Count + " " + D_S_Count;
  537.         return res;
  538.     } //viewAllSchemeBuffs$getBuffCount
  539.  
  540.     private String viewAllSchemeBuffs(String scheme, String page, String action)
  541.     {
  542.         List<String> buffList = new ArrayList<>();
  543.         String HTML_MESSAGE = "<html><head><title>" + TITLE_NAME + "</title></head><body><center><br>";
  544.         String[] eventSplit = viewAllSchemeBuffs$getBuffCount(scheme).split(" ");
  545.         int TOTAL_BUFF = Integer.parseInt(eventSplit[0]);
  546.         int BUFF_COUNT = Integer.parseInt(eventSplit[1]);
  547.         int DANCE_SONG = Integer.parseInt(eventSplit[2]);
  548.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  549.         {
  550.             if (action.equals("add")) {
  551.                 HTML_MESSAGE += "You can add <font color=LEVEL>" + (MAX_SCHEME_BUFFS - BUFF_COUNT) + "</font> Buffs and <font color=LEVEL>" + (MAX_SCHEME_DANCES - DANCE_SONG) + "</font> Dances more!";
  552.                 String QUERY = "SELECT * FROM npcbuffer_buff_list WHERE buffType IN (" + generateQuery(BUFF_COUNT, DANCE_SONG) + ") AND canUse=1 ORDER BY Buff_Class ASC, id";
  553.                 PreparedStatement getBuffCount = con.prepareStatement(QUERY);
  554.                 ResultSet rss = getBuffCount.executeQuery();
  555.                 while (rss.next()) {
  556.                     String name = SkillTable.getInstance().getInfo(rss.getInt("buffId"), rss.getInt("buffLevel")).getName();
  557.                     name = name.replace(" ", "+");
  558.                     buffList.add(name + "_" + rss.getInt("buffId") + "_" + rss.getInt("buffLevel"));
  559.                 }
  560.             }
  561.             else if (action.equals("remove")) {
  562.                 HTML_MESSAGE += "You have <font color=LEVEL>" + BUFF_COUNT + "</font> Buffs and <font color=LEVEL>" + DANCE_SONG + "</font> Dances";
  563.                 String QUERY = "SELECT * FROM npcbuffer_scheme_contents WHERE scheme_id=? ORDER BY Buff_Class ASC, id";
  564.                 PreparedStatement getBuffCount = con.prepareStatement(QUERY);
  565.                 getBuffCount.setString(1, scheme);
  566.                 ResultSet rss = getBuffCount.executeQuery();
  567.                 while (rss.next()) {
  568.                     String name = SkillTable.getInstance().getInfo(rss.getInt("skill_id"), rss.getInt("skill_level")).getName();
  569.                     name = name.replace(" ", "+");
  570.                     buffList.add(name + "_" + rss.getInt("skill_id") + "_" + rss.getInt("skill_level"));
  571.                 }
  572.             }
  573.             else if (DEBUG) throw new RuntimeException();
  574.         }
  575.       //catch (SQLException e) { //TODO:
  576.       //        buffList.clear();
  577.       //        count = 0;
  578.       //}
  579.         catch (SQLException e) { print(e); }
  580.  
  581.         HTML_MESSAGE += "<BR1><table border=0><tr>";
  582.         final int buffsPerPage = 20;
  583.         final String width, pageName;
  584.         int pc = (buffList.size() - 1) / buffsPerPage + 1;
  585.         if (pc > 5) {
  586.             width = "25";
  587.             pageName = "P";
  588.         } else {
  589.             width = "50";
  590.             pageName = "Page ";
  591.         }
  592.         for (int ii = 1; ii <= pc; ++ii)
  593.             if (ii == Integer.parseInt(page)) HTML_MESSAGE += "<td width=" + width + " align=center><font color=LEVEL>" + pageName + ii + "</font></td>";
  594.             else if (action.equals("add"))    HTML_MESSAGE += "<td width=" + width + ">" + "<button value=\"" + pageName + ii + "\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " manage_scheme_1 " + scheme + " " + ii + " x\" width=" + width + " height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>";
  595.             else if (action.equals("remove")) HTML_MESSAGE += "<td width=" + width + ">" + "<button value=\"" + pageName + ii + "\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " manage_scheme_2 " + scheme + " " + ii + " x\" width=" + width + " height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>";
  596.             else if (DEBUG) throw new RuntimeException();
  597.         HTML_MESSAGE += "</tr></table>";
  598.  
  599.         int limit = buffsPerPage * Integer.parseInt(page);
  600.         int start = limit - buffsPerPage;
  601.         int end = Math.min(limit, buffList.size());
  602.         int k=0;
  603.         for (int i = start; i < end; ++i) {
  604.             String value = buffList.get(i);
  605.             value = value.replace("_", " ");
  606.             String[] extr = value.split(" ");
  607.             String name = extr[0];
  608.             name = name.replace("+", " ");
  609.             int id = Integer.parseInt(extr[1]);
  610.             int level = Integer.parseInt(extr[2]);
  611.             /*--String page = extr[3];--*/
  612.             if (action.equals("add")) {
  613.                 if (!isUsed(scheme, id, level)) {
  614.                     if (k % 2 != 0) HTML_MESSAGE += "<BR1><table border=0 bgcolor=333333>";
  615.                     else            HTML_MESSAGE += "<BR1><table border=0 bgcolor=292929>";
  616.                     HTML_MESSAGE += "<tr><td width=35>" + getSkillIconHtml(id, level) + "</td><td fixwidth=170>" + name + "</td><td><button value=\"Add\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " add_buff " + scheme + "_" + id + "_" + level + " " + page + " " + TOTAL_BUFF + "\" width=65 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>"
  617.                                  +  "</tr></table>"; k+=1;
  618.                 }
  619.             }
  620.             else if (action.equals("remove")) {
  621.                 if (k % 2 != 0) HTML_MESSAGE += "<BR1><table border=0 bgcolor=333333>";
  622.                 else            HTML_MESSAGE += "<BR1><table border=0 bgcolor=292929>";
  623.                 HTML_MESSAGE += "<tr><td width=35>" + getSkillIconHtml(id, level) + "</td><td fixwidth=170>" + name + "</td><td><button value=\"Remove\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " remove_buff " + scheme + "_" + id + "_" + level + " " + page + " " + TOTAL_BUFF + "\" width=65 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>"
  624.                              +  "</table>"; k+=1;
  625.             }
  626.         }
  627.         HTML_MESSAGE += "<br><br><button value=\"Back\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " manage_scheme_select " + scheme + " x x\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  628.                      +  "<button value=\"Home\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect main 0 0\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  629.                      +  "<br><font color=303030>" + TITLE_NAME + "</font></center></body></html>";
  630.         return HTML_MESSAGE;
  631.     } //viewAllSchemeBuffs
  632.  
  633.     private String viewAllBuffTypes()
  634.     {
  635.         String HTML_MESSAGE = "<html><head><title>" + TITLE_NAME + "</title></head><body><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>";
  636.         HTML_MESSAGE += "<font color=LEVEL>[Buff management]</font><br>";
  637.         if (ENABLE_BUFFS)
  638.             HTML_MESSAGE += "<button value=\"Buffs\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " edit_buff_list buff Buffs 1\" width=200 height=22 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  639.         if (ENABLE_RESIST)
  640.             HTML_MESSAGE += "<button value=\"Resist Buffs\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " edit_buff_list resist Resists 1\" width=200 height=22 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  641.         if (ENABLE_SONGS)
  642.             HTML_MESSAGE += "<button value=\"Songs\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " edit_buff_list song Songs 1\" width=200 height=22 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  643.         if (ENABLE_DANCES)
  644.             HTML_MESSAGE += "<button value=\"Dances\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " edit_buff_list dance Dances 1\" width=200 height=22 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  645.         if (ENABLE_CHANTS)
  646.             HTML_MESSAGE += "<button value=\"Chants\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " edit_buff_list chant Chants 1\" width=200 height=22 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  647.         if (ENABLE_SPECIAL)
  648.             HTML_MESSAGE += "<button value=\"Special Buffs\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " edit_buff_list special Special_Buffs 1\" width=200 height=22 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  649.         if (ENABLE_OTHERS)
  650.             HTML_MESSAGE += "<button value=\"Others Buffs\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " edit_buff_list others Others_Buffs 1\" width=200 height=22 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  651.         if (ENABLE_CUBIC)
  652.             HTML_MESSAGE += "<button value=\"Cubics\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " edit_buff_list cubic cubic_Buffs 1\" width=200 height=22 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
  653.         if (ENABLE_BUFF_SET)
  654.             HTML_MESSAGE += "<button value=\"Buff Sets\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " edit_buff_list set Buff_Sets 1\" width=200 height=22 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br>";
  655.         HTML_MESSAGE += "<button value=\"Back\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect main 0 0\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  656.                      +  "<br><font color=303030>" + TITLE_NAME + "</font></center></body></html>";
  657.         return HTML_MESSAGE;
  658.     }
  659.  
  660.     private String viewAllBuffs(String type, String typeName, String page)
  661.     {
  662.         List<String> buffList = new ArrayList<>();
  663.         String HTML_MESSAGE = "<html><head><title>" + TITLE_NAME + "</title></head><body><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>";
  664.         typeName = typeName.replace("_", " ");
  665.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  666.         {
  667.             final PreparedStatement getBuffCount;
  668.             if (type.equals("set")) {
  669.                 getBuffCount = con.prepareStatement("SELECT * FROM npcbuffer_buff_list WHERE buffType IN (" + generateQuery(0, 0) + ") AND canUse=1");
  670.             }
  671.             else {
  672.                 getBuffCount = con.prepareStatement("SELECT * FROM npcbuffer_buff_list WHERE buffType=?");
  673.                 getBuffCount.setString(1, type);
  674.             }
  675.             ResultSet rss = getBuffCount.executeQuery();
  676.             while (rss.next()) {
  677.                 String name = SkillTable.getInstance().getInfo(rss.getInt("buffId"), rss.getInt("buffLevel")).getName();
  678.                 name = name.replace(" ", "+");
  679.                 String usable = rss.getString("canUse");
  680.                 String forClass = rss.getString("forClass");
  681.                 String skill_id = rss.getString("buffId");
  682.                 String skill_level = rss.getString("buffLevel");
  683.                 buffList.add(name + "_" + forClass + "_" + page + "_" + usable + "_" + skill_id + "_" + skill_level);
  684.             }
  685.         }
  686.       //catch (SQLException e) { //TODO:
  687.       //        buffList.clear();
  688.       //        count = 0;
  689.       //}
  690.         catch (SQLException e) { print(e); }
  691.         Collections.sort(buffList);
  692.  
  693.         HTML_MESSAGE += "<font color=LEVEL>[Buff management - " + typeName + " - Page " + page + "]</font><br><table border=0><tr>";
  694.         final int buffsPerPage;
  695.         if (type.equals("set")) buffsPerPage = 12;
  696.         else buffsPerPage = 20;
  697.         final String width, pageName;
  698.         int pc = (buffList.size() - 1) / buffsPerPage + 1;
  699.         if (pc > 5) {
  700.             width = "25";
  701.             pageName = "P";
  702.         } else {
  703.             width = "50";
  704.             pageName = "Page ";
  705.         }
  706.         typeName = typeName.replace(" ", "_");
  707.         for (int ii = 1; ii <= pc; ++ii)
  708.             if (ii == Integer.parseInt(page)) HTML_MESSAGE += "<td width=" + width + " align=center><font color=LEVEL>" + pageName + ii + "</font></td>";
  709.             else HTML_MESSAGE += "<td width=" + width + "><button value=\"" + pageName + "" + ii + "\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " edit_buff_list " + type + " " + typeName + " " + ii + "\" width=" + width + " height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>";
  710.         HTML_MESSAGE += "</tr></table><br>";
  711.  
  712.         int limit = buffsPerPage * Integer.parseInt(page);
  713.         int start = limit - buffsPerPage;
  714.         int end = Math.min(limit, buffList.size());
  715.         for (int i = start; i < end; ++i) {
  716.             String value = buffList.get(i);
  717.             value = value.replace("_", " ");
  718.             String[] extr = value.split(" ");
  719.             String name = extr[0];
  720.             name = name.replace("+", " ");
  721.             int forClass = Integer.parseInt(extr[1]);
  722.             /*page = extr[2];*/
  723.             int usable = Integer.parseInt(extr[3]);
  724.             String skillPos = extr[4] + "_" + extr[5];
  725.             if (i % 2 != 0) HTML_MESSAGE += "<BR1><table border=0 bgcolor=333333>";
  726.             else            HTML_MESSAGE += "<BR1><table border=0 bgcolor=292929>";
  727.             if (type.equals("set")) {
  728.                 String listOrder = null;
  729.                 if (forClass == 0)
  730.                     listOrder = "List=\"" + SET_FIGHTER + ";" + SET_MAGE + ";" + SET_ALL + ";" + SET_NONE + ";\"";
  731.                 else if (forClass == 1)
  732.                     listOrder = "List=\"" + SET_MAGE + ";" + SET_FIGHTER + ";" + SET_ALL + ";" + SET_NONE + ";\"";
  733.                 else if (forClass == 2)
  734.                     listOrder = "List=\"" + SET_ALL + ";" + SET_FIGHTER + ";" + SET_MAGE + ";" + SET_NONE + ";\"";
  735.                 else if (forClass == 3)
  736.                     listOrder = "List=\"" + SET_NONE + ";" + SET_FIGHTER + ";" + SET_MAGE + ";" + SET_ALL + ";\"";
  737.                 HTML_MESSAGE += "<tr><td fixwidth=145>" + name + "</td><td width=70><combobox var=\"newSet" + i + "\" width=70 " + listOrder + "></td>"
  738.                              +  "<td width=50><button value=\"Update\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " changeBuffSet " + skillPos + " $newSet" + i + " " + page + "\" width=50 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>";
  739.             }
  740.             else {
  741.                 HTML_MESSAGE += "<tr><td fixwidth=170>" + name + "</td><td width=80>";
  742.                 if (usable == 1)      HTML_MESSAGE += "<button value=\"Disable\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " editSelectedBuff " + skillPos + " 0-" + page + " " + type + "\" width=80 height=22 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>";
  743.                 else if (usable == 0) HTML_MESSAGE += "<button value=\"Enable\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " editSelectedBuff " + skillPos + " 1-" + page + " " + type + "\" width=80 height=22 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>";
  744.             }
  745.             HTML_MESSAGE += "</table>";
  746.         }
  747.         HTML_MESSAGE += "<br><br><button value=\"Back\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect manage_buffs 0 0\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  748.                      +  "<button value=\"Home\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " redirect main 0 0\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  749.                      +  "<br><font color=303030>" + TITLE_NAME + "</font></center></body></html>";
  750.         return HTML_MESSAGE;
  751.     }
  752.  
  753.     private void manageSelectedBuff(String buffPosId, String canUseBuff)
  754.     {
  755.         String[] bpid = buffPosId.split("_");
  756.         String bId = bpid[0];
  757.         String bLvl = bpid[1];
  758.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  759.         {
  760.             PreparedStatement upd = con.prepareStatement("UPDATE npcbuffer_buff_list SET canUse=? WHERE buffId=? AND buffLevel=? LIMIT 1");
  761.             upd.setString(1, canUseBuff);
  762.             upd.setString(2, bId);
  763.             upd.setString(3, bLvl);
  764.             upd.executeUpdate();
  765.             upd.close();
  766.         }
  767.         catch (SQLException e) { print(e); }
  768.     }
  769.  
  770.     private String manageSelectedSet(String id, String newVal, String opt3)
  771.     {
  772.         String[] bpid = id.split("_");
  773.         String bId = bpid[0];
  774.         String bLvl = bpid[1];
  775.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  776.         {
  777.             PreparedStatement upd = con.prepareStatement("UPDATE npcbuffer_buff_list SET forClass=? WHERE buffId=? AND bufflevel=?");
  778.             upd.setString(1, newVal);
  779.             upd.setString(2, bId);
  780.             upd.setString(3, bLvl);
  781.             upd.executeUpdate();
  782.             upd.close();
  783.         }
  784.         catch (SQLException e) { print(e); }
  785.         return viewAllBuffs("set", "Buff Sets", opt3);
  786.     }
  787.  
  788.     private void addTimeout(QuestState st, int gaugeColor, int amount, int offset)
  789.     {
  790.         int endtime = (int) ((System.currentTimeMillis() + amount * 1000) / 1000);
  791.         st.set("blockUntilTime", String.valueOf(endtime));
  792.         st.getPlayer().sendPacket(new SetupGauge(gaugeColor, amount * 1000 + offset));
  793.     }
  794.  
  795.     private void heal(L2PcInstance player, boolean isPet)
  796.     {
  797.         L2Summon target;
  798.         if (!isPet) {
  799.             PcStatus pcStatus = player.getStatus();
  800.             PcStat pcStat = player.getStat();
  801.             pcStatus.setCurrentMp(pcStat.getMaxMp());
  802.         }
  803.         else if (/*isPet &&*/ (target = player.getPet()) != null) {
  804.             SummonStatus petStatus = target.getStatus();
  805.             SummonStat petStat = target.getStat();
  806.             petStatus.setCurrentMp(petStat.getMaxMp());
  807.             if (target instanceof L2PetInstance) {
  808.                 L2PetInstance pet = (L2PetInstance) target;
  809.                 pet.setCurrentFed(pet.getMaxFed());
  810.                 player.sendPacket(new SetSummonRemainTime(pet.getMaxFed(), pet.getCurrentFed()));
  811.             }
  812.             else if (target instanceof L2SummonInstance) {
  813.                 L2SummonInstance summon = (L2SummonInstance) target;
  814.                 summon.decTimeRemaining(summon.getTimeRemaining() - summon.getTotalLifeTime());
  815.                 player.sendPacket(new SetSummonRemainTime(summon.getTotalLifeTime(), summon.getTimeRemaining()));
  816.             }
  817.             else if (DEBUG) throw new RuntimeException();
  818.         }
  819.     }
  820.  
  821.     @Override
  822.     public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  823.     {
  824.         //TRACE("onAdvEvent('"+event+"',"+(npc == null ? "NULL" : npc.getNpcId()+npc.getName())+","+(player == null ? "NULL" : player.getName())+")");/*@IF DEBUG@*/
  825.         if (DEBUG) System.out.println(getScriptName() + "#onAdvEvent('" + event + "'," + (npc == null ? "NULL" : npc.getNpcId() + npc.getName()) + "," + (player == null ? "NULL" : player.getName()) + ")");
  826.         QuestState st = player.getQuestState(QUEST_LOADING_INFO);
  827.         String[] eventSplit = event.split(" ", 4); if (eventSplit.length != 4) { player.sendPacket(SystemMessageId.INCORRECT_NAME_TRY_AGAIN); return null; }
  828.     /*--String[] eventSplit = event.split(" ");--*/
  829.         String eventParam0 = eventSplit[0];
  830.         String eventParam1 = eventSplit[1];
  831.         String eventParam2 = eventSplit[2];
  832.         String eventParam3 = eventSplit[3];
  833.  
  834.         switch (eventParam0) {
  835.             case "reloadscript":
  836.                 if (eventParam1.equals("1")) return reloadConfig(st);
  837.                 if (eventParam1.equals("0")) return rebuildMainHtml(st);
  838.                 if (DEBUG) throw new RuntimeException();
  839.  
  840.             case "redirect":
  841.                 switch (eventParam1) {
  842.                     case "main": return rebuildMainHtml(st);
  843.                     case "manage_buffs": return viewAllBuffTypes();
  844.                     /**/
  845.                     case "view_buffs" : return buildHtml("buff");
  846.                     case "view_resists" : return buildHtml("resist");
  847.                     case "view_songs" : return buildHtml("song");
  848.                     case "view_dances" : return buildHtml("dance");
  849.                     case "view_chants" : return buildHtml("chant");
  850.                     case "view_others" : return buildHtml("others");
  851.                     case "view_special" : return buildHtml("special");
  852.                     case "view_cubic" : return buildHtml("cubic");
  853.                     default: if (DEBUG) throw new RuntimeException();
  854.                 }
  855.                 /*break;*/
  856.  
  857.             case "buffpet":
  858.                 if ((int)(System.currentTimeMillis()/1000) > st.getInt("blockUntilTime")) {
  859.                     st.set("Pet-On-Off", eventParam1);
  860.                     if (TIME_OUT) addTimeout(st, 3, TIME_OUT_TIME / 2, 600);
  861.                 }
  862.                 return rebuildMainHtml(st);
  863.  
  864.             case "create":
  865.             {
  866.                 String param = eventParam1.replaceAll("[ !"+"\""+"#$%&'()*+,/:;<=>?@"+"\\["+"\\\\"+"\\]"+"\\^"+"`{|}~]", "");   //JOJO
  867.                 if (param.length() == 0 || param.equals("no_name")) {
  868.                     player.sendPacket(SystemMessageId.INCORRECT_NAME_TRY_AGAIN);
  869.                     return showText(st, "Info", "Please, enter the scheme name!", true, "Return", "main");
  870.                 }
  871.                 else {
  872.                     try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  873.                     {
  874.                         PreparedStatement ins = con.prepareStatement("INSERT INTO npcbuffer_scheme_list (player_id,scheme_name) VALUES (?,?)");
  875.                         ins.setInt(1, player.getObjectId());
  876.                         ins.setString(2, param);
  877.                         ins.executeUpdate();
  878.                         ins.close();
  879.                     }
  880.                     catch (SQLException e) { print(e); }
  881.                 }
  882.                 return rebuildMainHtml(st);
  883.             }
  884.  
  885.             case "delete":
  886.                 try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  887.                 {
  888.                     PreparedStatement rem;
  889.                     rem = con.prepareStatement("DELETE FROM npcbuffer_scheme_list WHERE id=? LIMIT 1");
  890.                     rem.setString(1, eventParam1);
  891.                     rem.executeUpdate();
  892.                     rem.close();
  893.                     rem = con.prepareStatement("DELETE FROM npcbuffer_scheme_contents WHERE scheme_id=?");
  894.                     rem.setString(1, eventParam1);
  895.                     rem.executeUpdate();
  896.                     rem.close();
  897.                 }
  898.                 catch (SQLException e) { print(e); }
  899.                 return rebuildMainHtml(st);
  900.  
  901.             case "delete_c":
  902.                 return "<html><head><title>" + TITLE_NAME + "</title></head><body><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>Do you really want to delete '" + eventParam2 + "' scheme?<br><br>"
  903.                      +  "<button value=\"Yes\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " delete " + eventParam1 + " x x\" width=50 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  904.                      +  "<button value=\"No\" action=\"bypass -h Quest " + QUEST_LOADING_INFO + " delete_1 x x x\" width=50 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">"
  905.                      +  "<br><font color=303030>" + TITLE_NAME + "</font></center></body></html>";
  906.  
  907.             case "create_1": return createScheme();
  908.             case "edit_1" :return editScheme(player);
  909.             case "delete_1": return deleteScheme(player);
  910.             case "manage_scheme_1": return viewAllSchemeBuffs(eventParam1, eventParam2, "add");
  911.             case "manage_scheme_2": return viewAllSchemeBuffs(eventParam1, eventParam2, "remove");
  912.             case "manage_scheme_select": return getOptionList(eventParam1);
  913.  
  914.             case "remove_buff":
  915.             {
  916.                 String[] split = eventParam1.split("_");
  917.                 String scheme = split[0];
  918.                 String skill = split[1];
  919.                 String level = split[2];
  920.                 try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  921.                 {
  922.                     PreparedStatement rem = con.prepareStatement("DELETE FROM npcbuffer_scheme_contents WHERE scheme_id=? AND skill_id=? AND skill_level=? LIMIT 1");
  923.                     rem.setString(1, scheme);
  924.                     rem.setString(2, skill);
  925.                     rem.setString(3, level);
  926.                     rem.executeUpdate();
  927.                 }
  928.                 catch (SQLException e) { print(e); }
  929.                 int temp = Integer.parseInt(eventParam3) - 1;
  930.                 final String HTML;
  931.                 if (temp <= 0) HTML = getOptionList(scheme);
  932.                 else HTML = viewAllSchemeBuffs(scheme, eventParam2, "remove");
  933.                 return HTML;
  934.             }
  935.  
  936.             case "add_buff":
  937.             {
  938.                 String[] split = eventParam1.split("_");
  939.                 String scheme = split[0];
  940.                 String skill = split[1];
  941.                 String level = split[2];
  942.                 int idbuffclass = getClassBuff(skill);
  943.                 try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  944.                 {
  945.                     PreparedStatement ins = con.prepareStatement("INSERT INTO npcbuffer_scheme_contents (scheme_id,skill_id,skill_level,buff_class) VALUES (?,?,?,?)");
  946.                     ins.setString(1, scheme);
  947.                     ins.setString(2, skill);
  948.                     ins.setString(3, level);
  949.                     ins.setInt(4, idbuffclass);
  950.                     ins.executeUpdate();
  951.                     ins.close();
  952.                 }
  953.                 catch (SQLException e) { print(e); }
  954.                 int temp = Integer.parseInt(eventParam3) + 1;
  955.                 final String HTML;
  956.                 if (temp >= MAX_SCHEME_BUFFS + MAX_SCHEME_DANCES) HTML = getOptionList(scheme);
  957.                 else HTML = viewAllSchemeBuffs(scheme, eventParam2, "add");
  958.                 return HTML;
  959.             }
  960.  
  961.             case "edit_buff_list":
  962.                 return viewAllBuffs(eventParam1, eventParam2, eventParam3);
  963.  
  964.             case "changeBuffSet":
  965.                 if (eventParam2.equals(SET_FIGHTER)) eventParam2 = "0";
  966.                 else if (eventParam2.equals(SET_MAGE)) eventParam2 = "1";
  967.                 else if (eventParam2.equals(SET_ALL)) eventParam2 = "2";
  968.                 else if (eventParam2.equals(SET_NONE)) eventParam2 = "3";
  969.                 else if (DEBUG) throw new RuntimeException();
  970.                 return manageSelectedSet(eventParam1, eventParam2, eventParam3);
  971.  
  972.             case "editSelectedBuff":
  973.             {
  974.                 eventParam2 = eventParam2.replace("-", " ");
  975.                 String[] split = eventParam2.split(" ");
  976.                 String action = split[0];
  977.                 String page = split[1];
  978.                 manageSelectedBuff(eventParam1, action);
  979.                 final String typeName;
  980.                 switch (eventParam3) {
  981.                     case "buff": typeName = "Buffs"; break;
  982.                     case "resist": typeName = "Resists"; break;
  983.                     case "song": typeName = "Songs"; break;
  984.                     case "dance": typeName = "Dances"; break;
  985.                     case "chant": typeName = "Chants"; break;
  986.                     case "others": typeName = "Others_Buffs"; break;
  987.                     case "special": typeName = "Special_Buffs"; break;
  988.                     case "cubic": typeName = "Cubics"; break;
  989.                     default: /*if (DEBUG)*/ throw new RuntimeException();
  990.                 }
  991.                 return viewAllBuffs(eventParam3, typeName, page);
  992.             }
  993.  
  994.             case "viewSelectedConfig": throw new RuntimeException();//TODO: return viewSelectedConfig(eventParam1,eventParam2);
  995.  
  996.             case "changeConfig": throw new RuntimeException();//TODO: return updateConfigValue(eventParam1,eventParam2,eventParam3);
  997.  
  998.             case "heal":
  999.                 if ((int)(System.currentTimeMillis()/1000) > st.getInt("blockUntilTime")) {
  1000.                     if (st.getQuestItemsCount(CONSUMABLE_ID) < HEAL_PRICE)
  1001.                         return showText(st, "Sorry", "You don't have the enough items:<br>You need: <font color=LEVEL>" + HEAL_PRICE + " " + getItemNameHtml(st, CONSUMABLE_ID) + "!", false, "0", "0");
  1002.                     else {
  1003.                         final boolean getpetbuff = isPetBuff(st);
  1004.                         if (getpetbuff) {
  1005.                             if (player.getPet() != null) heal(player, getpetbuff);
  1006.                             else return showText(st, "Info", "You can't use the Pet's options.<br>Summon your pet first!", false, "Return", "main");
  1007.                         }
  1008.                         else heal(player, getpetbuff);
  1009.                         st.takeItems(CONSUMABLE_ID, HEAL_PRICE);
  1010.                         if (TIME_OUT) addTimeout(st, 1, TIME_OUT_TIME / 2, 600);
  1011.                     }
  1012.                 }
  1013.                 return SMART_WINDOW ? null : rebuildMainHtml(st);
  1014.  
  1015.             case "removeBuffs":
  1016.                 if ((int)(System.currentTimeMillis()/1000) > st.getInt("blockUntilTime")) {
  1017.                     if (st.getQuestItemsCount(CONSUMABLE_ID) < BUFF_REMOVE_PRICE)
  1018.                         return showText(st, "Sorry", "You don't have the enough items:<br>You need: <font color=LEVEL>" + BUFF_REMOVE_PRICE + " " + getItemNameHtml(st, CONSUMABLE_ID) + "!", false, "0", "0");
  1019.                     else {
  1020.                         final boolean getpetbuff = isPetBuff(st);
  1021.                         if (getpetbuff) {
  1022.                             if (player.getPet() != null) player.getPet().stopAllEffects();
  1023.                             else return showText(st, "Info", "You can't use the Pet's options.<br>Summon your pet first!", false, "Return", "main");
  1024.                         }
  1025.                         else {
  1026.                             player.stopAllEffects();
  1027.                             if (player.getCubics() != null) {
  1028.                                 for (L2CubicInstance cubic : player.getCubics().valueCollection()) {
  1029.                                     cubic.stopAction();
  1030.                                     player.delCubic(cubic.getId());
  1031.                                 }
  1032.                             }
  1033.                         }
  1034.                         st.takeItems(CONSUMABLE_ID, BUFF_REMOVE_PRICE);
  1035.                         if (TIME_OUT) addTimeout(st, 2, TIME_OUT_TIME / 2, 600);
  1036.                     }
  1037.                 }
  1038.                 return SMART_WINDOW ? null : rebuildMainHtml(st);
  1039.  
  1040.             case "cast":
  1041.                 if ((int)(System.currentTimeMillis()/1000) > st.getInt("blockUntilTime")) {
  1042.                     TIntArrayList buffs = new TIntArrayList();
  1043.                     TIntArrayList levels = new TIntArrayList();
  1044.                     try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1045.                     {
  1046.                         PreparedStatement rss = con.prepareStatement("SELECT * FROM npcbuffer_scheme_contents WHERE scheme_id=? ORDER BY id");
  1047.                         rss.setString(1, eventParam1);
  1048.                         ResultSet action = rss.executeQuery();
  1049.                         while (action.next()) {
  1050.                           //enabled = 1;
  1051.                             int id = Integer.parseInt(action.getString("skill_id"));
  1052.                             int level = Integer.parseInt(action.getString("skill_level"));
  1053.                             switch (getBuffType(id)) {
  1054.                             case "buff":
  1055.                                 if (ENABLE_BUFFS)
  1056.                                     if (isEnabled(id, level)) {
  1057.                                         buffs.add(id);
  1058.                                         levels.add(level);
  1059.                                     }
  1060.                                 break;
  1061.                             case "resist":
  1062.                                 if (ENABLE_RESIST)
  1063.                                     if (isEnabled(id, level)) {
  1064.                                         buffs.add(id);
  1065.                                         levels.add(level);
  1066.                                     }
  1067.                                 break;
  1068.                             case "song":
  1069.                                 if (ENABLE_SONGS)
  1070.                                     if (isEnabled(id, level)) {
  1071.                                         buffs.add(id);
  1072.                                         levels.add(level);
  1073.                                     }
  1074.                                 break;
  1075.                             case "dance":
  1076.                                 if (ENABLE_DANCES)
  1077.                                     if (isEnabled(id, level)) {
  1078.                                         buffs.add(id);
  1079.                                         levels.add(level);
  1080.                                     }
  1081.                                 break;
  1082.                             case "chant":
  1083.                                 if (ENABLE_CHANTS)
  1084.                                     if (isEnabled(id, level)) {
  1085.                                         buffs.add(id);
  1086.                                         levels.add(level);
  1087.                                     }
  1088.                                 break;
  1089.                             case "others":
  1090.                                 if (ENABLE_OTHERS)
  1091.                                     if (isEnabled(id, level)) {
  1092.                                         buffs.add(id);
  1093.                                         levels.add(level);
  1094.                                     }
  1095.                                 break;
  1096.                             case "special":
  1097.                                 if (ENABLE_SPECIAL)
  1098.                                     if (isEnabled(id, level)) {
  1099.                                         buffs.add(id);
  1100.                                         levels.add(level);
  1101.                                     }
  1102.                                 break;
  1103.                             default:
  1104.                                 if (DEBUG) throw new RuntimeException();
  1105.                             } //switch getBuffType(id)
  1106.                         } //while action.next()
  1107.                     } //con
  1108.                   //catch (SQLException e) { print "Query error!"; } //TODO:
  1109.                     catch (SQLException e) { print(e); }
  1110.  
  1111.                     if (buffs.size() == 0)
  1112.                         return viewAllSchemeBuffs(eventParam1, "1", "add");
  1113.                     else {
  1114.                         if (!FREE_BUFFS)
  1115.                             if (st.getQuestItemsCount(CONSUMABLE_ID) < SCHEME_BUFF_PRICE)
  1116.                                 return showText(st, "Sorry", "You don't have the enough items:<br>You need: <font color=LEVEL>" + SCHEME_BUFF_PRICE + " " + getItemNameHtml(st, CONSUMABLE_ID) + "!", false, "0", "0");
  1117.  
  1118.                         final boolean getpetbuff = isPetBuff(st);
  1119.                         for (int i = 0; i < buffs.size(); ++i) {
  1120.                             if (!getpetbuff) SkillTable.getInstance().getInfo(buffs.get(i), levels.get(i)).getEffects(player, player);
  1121.                             else {
  1122.                                 if (player.getPet() != null) SkillTable.getInstance().getInfo(buffs.get(i), levels.get(i)).getEffects(player.getPet(), player.getPet());
  1123.                                 else return showText(st, "Info", "You can't use the Pet's options.<br>Summon your pet first!", false, "Return", "main");
  1124.                             }
  1125.                         }
  1126.                         st.takeItems(CONSUMABLE_ID, SCHEME_BUFF_PRICE);
  1127.                         if (TIME_OUT) addTimeout(st, 3, TIME_OUT_TIME, 600);
  1128.                     }
  1129.                 }
  1130.                 return SMART_WINDOW ? null : rebuildMainHtml(st);
  1131.  
  1132.             case "giveBuffs":
  1133.             {
  1134.                 final int cost;
  1135.                 switch (eventParam3) {
  1136.                     case "buff" : cost = BUFF_PRICE; break;
  1137.                     case "resist" : cost = RESIST_PRICE; break;
  1138.                     case "song" : cost = SONG_PRICE; break;
  1139.                     case "dance" : cost = DANCE_PRICE; break;
  1140.                     case "chant" : cost = CHANT_PRICE; break;
  1141.                     case "others" : cost = OTHERS_PRICE; break;
  1142.                     case "special" : cost = SPECIAL_PRICE; break;
  1143.                     case "cubic" : cost = CUBIC_PRICE; break;
  1144.                     default: /*if (DEBUG)*/ throw new RuntimeException();
  1145.                 }
  1146.  
  1147.                 if ((int)(System.currentTimeMillis()/1000) > st.getInt("blockUntilTime")) {
  1148.                     if (!FREE_BUFFS)
  1149.                         if (st.getQuestItemsCount(CONSUMABLE_ID) < cost)
  1150.                             return showText(st, "Sorry", "You don't have the enough items:<br>You need: <font color=LEVEL>" + cost + " " + getItemNameHtml(st, CONSUMABLE_ID) + "!", false, "0", "0");
  1151.                     L2Skill skill = SkillTable.getInstance().getInfo(Integer.parseInt(eventParam1), Integer.parseInt(eventParam2));
  1152.                     if (skill.getSkillType() == L2SkillType.SUMMON)
  1153.                         if (st.getQuestItemsCount(skill.getItemConsumeId()) < skill.getItemConsume())
  1154.                             return showText(st, "Sorry", "You don't have the enough items:<br>You need: <font color=LEVEL>" + skill.getItemConsume() + " " + getItemNameHtml(st, skill.getItemConsumeId()) + "!", false, "0", "0");
  1155.                     final boolean getpetbuff = isPetBuff(st);
  1156.                     if (!getpetbuff) {
  1157.                         if (eventParam3.equals("cubic")) {
  1158.                             if (player.getCubics() != null) {
  1159.                                 for (L2CubicInstance cubic : player.getCubics().valueCollection()) {
  1160.                                     cubic.stopAction();
  1161.                                     player.delCubic(cubic.getId());
  1162.                                 }
  1163.                             }
  1164.                             player.useMagic(SkillTable.getInstance().getInfo(Integer.parseInt(eventParam1), Integer.parseInt(eventParam2)), false, false);
  1165.                         }
  1166.                         else SkillTable.getInstance().getInfo(Integer.parseInt(eventParam1), Integer.parseInt(eventParam2)).getEffects(player, player);
  1167.                     }
  1168.                     else {
  1169.                         if (eventParam3.equals("cubic")) {
  1170.                             if (player.getCubics() != null) {
  1171.                                 for (L2CubicInstance cubic : player.getCubics().valueCollection()) {
  1172.                                     cubic.stopAction();
  1173.                                     player.delCubic(cubic.getId());
  1174.                                 }
  1175.                             }
  1176.                             player.useMagic(SkillTable.getInstance().getInfo(Integer.parseInt(eventParam1), Integer.parseInt(eventParam2)), false, false);
  1177.                         }
  1178.                         else {
  1179.                             if (player.getPet() != null) SkillTable.getInstance().getInfo(Integer.parseInt(eventParam1), Integer.parseInt(eventParam2)).getEffects(player.getPet(), player.getPet());
  1180.                             else return showText(st, "Info", "You can't use the Pet's options.<br>Summon your pet first!", false, "Return", "main");
  1181.                         }
  1182.                     }
  1183.                     st.takeItems(CONSUMABLE_ID, cost);
  1184.                     if (TIME_OUT) addTimeout(st, 3, TIME_OUT_TIME / 10, 600);
  1185.                 }
  1186.                 return SMART_WINDOW ? null : buildHtml(eventParam3);
  1187.             }
  1188.  
  1189.             case "castBuffSet":
  1190.                 if ((int)(System.currentTimeMillis()/1000) > st.getInt("blockUntilTime")) {
  1191.                     if (!FREE_BUFFS)
  1192.                         if (st.getQuestItemsCount(CONSUMABLE_ID) < BUFF_SET_PRICE)
  1193.                             return showText(st, "Sorry", "You don't have the enough items:<br>You need: <font color=LEVEL>" + BUFF_SET_PRICE + " " + getItemNameHtml(st, CONSUMABLE_ID) + "!", false, "0", "0");
  1194.                     List<int[]> buff_sets = new ArrayList<>();
  1195.                     final int player_class;
  1196.                     if (player.isMageClass()) player_class = 1;
  1197.                     else player_class = 0;
  1198.                     final boolean getpetbuff = isPetBuff(st);
  1199.                     if (!getpetbuff) {
  1200.                         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1201.                         {
  1202.                             PreparedStatement getSimilarNameCount = con.prepareStatement("SELECT buffId,buffLevel FROM npcbuffer_buff_list WHERE forClass IN (?,?) ORDER BY id ASC");
  1203.                             getSimilarNameCount.setInt(1, player_class);
  1204.                             getSimilarNameCount.setString(2, "2");
  1205.                             ResultSet rss = getSimilarNameCount.executeQuery();
  1206.                             while (rss.next()) {
  1207.                                 int id = rss.getInt("buffId");
  1208.                                 int lvl = rss.getInt("buffLevel");
  1209.                                 buff_sets.add(new int[]{id, lvl});
  1210.                             }
  1211.                         }
  1212.                       //catch (SQLException e) { buff_sets.clear(); } //TODO:
  1213.                         catch (SQLException e) { print(e); }
  1214.                         for (int[] i : buff_sets)
  1215.                             SkillTable.getInstance().getInfo(i[0], i[1]).getEffects(player, player);
  1216.                     }
  1217.                     else {
  1218.                         if (player.getPet() != null) {
  1219.                             try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1220.                             {
  1221.                                 PreparedStatement getSimilarNameCount = con.prepareStatement("SELECT buffId,buffLevel FROM npcbuffer_buff_list WHERE forClass IN (?,?) ORDER BY id ASC");
  1222.                                 getSimilarNameCount.setString(1, "0");
  1223.                                 getSimilarNameCount.setString(2, "2");
  1224.                                 ResultSet rss = getSimilarNameCount.executeQuery();
  1225.                                 while (rss.next()) {
  1226.                                     int id = rss.getInt("buffId");
  1227.                                     int lvl = rss.getInt("buffLevel");
  1228.                                     buff_sets.add(new int[]{id, lvl});
  1229.                                 }
  1230.                             }
  1231.                           //catch (SQLException e) { buff_sets.clear(); } //TODO:
  1232.                             catch (SQLException e) { print(e); }
  1233.                             for (int[] i : buff_sets)
  1234.                                 SkillTable.getInstance().getInfo(i[0], i[1]).getEffects(player.getPet(), player.getPet());
  1235.                         }
  1236.                         else return showText(st, "Info", "You can't use the Pet's options.<br>Summon your pet first!", false, "Return", "main");
  1237.                     }
  1238.                     st.takeItems(CONSUMABLE_ID, BUFF_SET_PRICE);
  1239.                     if (TIME_OUT) addTimeout(st, 3, TIME_OUT_TIME, 600);
  1240.                 }
  1241.                 return SMART_WINDOW ? null : rebuildMainHtml(st);
  1242.  
  1243.             case "description":
  1244.             {
  1245.                 int skillId = Integer.parseInt(eventParam1);
  1246.                 int level = Integer.parseInt(eventParam2);
  1247.                 String description = getSkillDescription(skillId, level);
  1248.                 if (description != null) {
  1249.                     if (player.isGM()) player.sendMessage("�X�L�‹Źî•ń " + skillId + "-" + level);
  1250.                     else player.sendMessage("�X�L�‹Źî•ń");
  1251.                     L2Skill skill = SkillTable.getInstance().getInfo(skillId, level);
  1252.                     player.sendMessage(skill.getName() + " �Ś�x�‹ " + level);
  1253.                     player.sendMessage(getSkillDescription(skillId, level));
  1254.                 }
  1255.                 return null;
  1256.             }
  1257.         } // switch (eventParam0)
  1258.         return rebuildMainHtml(st);
  1259.     }
  1260.  
  1261.     @Override
  1262.     public String onFirstTalk(L2Npc npc, L2PcInstance player)
  1263.     {
  1264.         QuestState st = player.getQuestState(QUEST_LOADING_INFO);
  1265.         if (st == null) st = newQuestState(player);
  1266.         if (player.isGM()) {
  1267.             if (SCRIPT_RELOAD) return reloadPanel(st);
  1268.             else return rebuildMainHtml(st);
  1269.         }
  1270.         else if ((int)(System.currentTimeMillis()/1000) > st.getInt("blockUntilTime")) {
  1271.             if (!ENABLE_VIP_BUFFER || ENABLE_VIP_BUFFER && player.getAccessLevel().getLevel() == VIP_ACCESS_LEVEL) {
  1272.                 if (!BUFF_WITH_KARMA && player.getKarma() > 0)
  1273.                     return showText(st, "Info", "You have too much <font color=FF0000>karma!</font><br>Come back,<br>when you don't have any karma!", false, "Return", "main");
  1274.                 else if (player.getLevel() < MIN_LEVEL)
  1275.                     return showText(st, "Info", "Your level is too low!<br>You have to be at least level <font color=LEVEL>" + MIN_LEVEL + "</font>,<br>to use my services!", false, "Return", "main");
  1276.                 else if (player.getPvpFlag() > 0)
  1277.                     return showText(st, "Info", "You can't buff while you are <font color=800080>flagged!</font><br>Wait some time and try again!", false, "Return", "main");
  1278.                 else if (player.isInCombat())
  1279.                     return showText(st, "Info", "You can't buff while you are attacking!<br>Stop your fight and try again!", false, "Return", "main");
  1280.                 else
  1281.                     return rebuildMainHtml(st);
  1282.             }
  1283.             else return showText(st, "Sorry", "This buffer is only for VIP's!<br>Contact the administrator for more info!", false, "Return", "main");
  1284.         }
  1285.         else return showText(st, "Sorry", "You have to wait a while!<br>if you wish to use my services!", false, "Return", "main");
  1286.     }
  1287.  
  1288.     @Override
  1289.     public boolean showResult(L2PcInstance player, String res)
  1290.     {
  1291.         if (SMART_WINDOW) {
  1292.             if (player != null && res != null && res.startsWith("<html>"))
  1293.             {
  1294.                 NpcHtmlMessage npcReply = new NpcHtmlMessage(5, 1); /*!*/
  1295.                 npcReply.setHtml(res);
  1296.                 player.sendPacket(npcReply);
  1297.                 player.sendPacket(ActionFailed.STATIC_PACKET);
  1298.                 return false;
  1299.             }
  1300.         }
  1301.         return super.showResult(player, res);
  1302.     }
  1303.  
  1304.     private String getSkillIconHtml(int id, int level)
  1305.     {
  1306.         String iconNumber = getSkillIconNumber(id, level);
  1307.         return "<button action=\"bypass -h Quest " + QUEST_LOADING_INFO + " description " + id + " " + level + " x\" width=32 height=32 back=\"Icon.skill" + iconNumber + "\" fore=\"Icon.skill" + iconNumber + "\">";
  1308.     }
  1309.  
  1310.     private String getSkillIconNumber(int id, int level)
  1311.     {
  1312.         String formato;
  1313.         if (id == 4) formato = "0004";
  1314.         else if (id > 9 && id < 100) formato = "00" + id;
  1315.         else if (id > 99 && id < 1000) formato = "0" + id;
  1316.         else if (id == 1517) formato = "1536";
  1317.         else if (id == 1518) formato = "1537";
  1318.         else if (id == 1547) formato = "0065";
  1319.         else if (id == 2076) formato = "0195";
  1320.         else if (id > 4550 && id < 4555) formato = "5739";
  1321.         else if (id > 4698 && id < 4701) formato = "1331";
  1322.         else if (id > 4701 && id < 4704) formato = "1332";
  1323.         else if (id == 6049) formato = "0094";
  1324.         else formato = String.valueOf(id);
  1325.         return formato;
  1326.     }
  1327.  
  1328.     private String getSkillDescription(int id, int level)
  1329.     {
  1330.         try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1331.         {
  1332.             PreparedStatement statement = con.prepareStatement("SELECT description FROM skillname_ja WHERE id=? AND level=?");
  1333.             statement.setInt(1, id);
  1334.             statement.setInt(2, level);
  1335.             ResultSet skillData = statement.executeQuery();
  1336.             if (skillData.next())
  1337.                 return skillData.getString("description");
  1338.         }
  1339.         catch (SQLException e) { print(e); }
  1340.         return null;
  1341.     }
  1342.  
  1343.     static public void main(String[] args)
  1344.     {
  1345.         new NpcBuffer(-1, QUEST_LOADING_INFO, "custom");
  1346.     }
  1347. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement