dymek84

NpcBuffer.java

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