Guest User

Buffer

a guest
May 14th, 2014
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.14 KB | None | 0 0
  1. package npc.model;
  2.  
  3. import java.util.regex.Pattern;
  4. import net.sf.l2j.Config;
  5. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  6. import net.sf.l2j.gameserver.templates.L2NpcTemplate;
  7. import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
  8. import java.util.StringTokenizer;
  9. import net.sf.l2j.Config;
  10. import net.sf.l2j.gameserver.cache.HtmCache;
  11. import net.sf.l2j.gameserver.datatables.SkillTable;
  12. import net.sf.l2j.gameserver.model.L2Skill;
  13. import net.sf.l2j.gameserver.model.L2Summon;
  14. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  15. import net.sf.l2j.gameserver.network.L2GameClient;
  16. import net.sf.l2j.gameserver.network.SystemMessageId;
  17. import net.sf.l2j.gameserver.serverpackets.ActionFailed;
  18. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  19. import net.sf.l2j.util.Rnd;
  20.  
  21. public class L2BufferInstance extends L2NpcInstance
  22. {
  23.     private static final Pattern patterns = Pattern.compile("[a-zA-Z0-9]{1,8}");
  24.     private static final int[][] groupStaticBuff = new int[][]
  25.     {
  26.        
  27.             {1068,3}, //Might
  28.             {1086,2}, //Haste
  29.             {1242,3}, //Death Whisper
  30.             {1062,2}, //Berserker Spirit
  31.             {4401,1}, //Empower
  32.             {1040,3}, //Shield
  33.             {1036,2}, //Magic Barrier
  34.        
  35.             {1243,6}, //Bless Shield
  36.             {1268,4}, //Vampiric Rage
  37.             {1078,6}, //Concentration
  38.             {1045,6}, //Blessed Body
  39.             {1077,3}, //Focus
  40.             {1270,3}, //Guidance
  41.             {1085,3}, //Acumen
  42.        
  43.             {1303,2}, //Wild Magic
  44.             {1035,4}, //Mental Shield
  45.             {1304,3}, //Advanced Block
  46.             {1087,3}, //Agility
  47.             {1259,4}, //Resist Shock
  48.             {1204,2}, //Wind Walk
  49.             {1048,6}, //Blessed Soul
  50.            
  51.             {275,1}, //Fury
  52.             {274,1}, //Fire
  53.             {272,1}, //Inspiration
  54.             {271,1}, //Warrior
  55.             {273,1}, //Mystic
  56.             {365,1}, //Siren
  57.             {276,1}, //Concentration
  58.             {310,1}, //Vampire
  59.            
  60.             {264,1}, //Earth
  61.             {268,1}, //Wind
  62.             {269,1}, //Hunter
  63.             {304,1}, //Vitality
  64.             {349,1}, //Renewal
  65.             {267,1}, //Warding
  66.             {364,1}, //Champion
  67.  
  68.             {1413,1}, //Magnus Chant
  69.             {1355,1}, //Pr. of Water
  70.             {1357,1}, //Pr. of Wind
  71.             {1356,1}, //Pr. of Fire
  72.             {1363,1} //Chant of Victory
  73.        
  74.     };
  75.  
  76.     private static final int countGroup = 3;
  77.     private static final int priceBuff = 20000;
  78.     private static final int priceСancel = 20000;
  79.     private static final int priceHeal = 20000;
  80.     private static final int buffTime =  3600;
  81.     private static final int maxCountBuffSelfGroup = 28;
  82.  
  83.     public L2BufferInstance(int objectId, L2NpcTemplate template)
  84.     {
  85.         super(objectId, template);
  86.     }
  87.    
  88.     @Override
  89.     public void showChatWindow(L2PcInstance player, int val)
  90.     {
  91.         if (player == null || player.isDead())
  92.         {
  93.             return;
  94.         }
  95.  
  96.         if (player.isCursedWeaponEquiped())
  97.         {
  98.             return;
  99.         }
  100.  
  101.         showMain(player);
  102.     }
  103.    
  104.  
  105.     @Override
  106.     public void onActionShift(L2GameClient client)
  107.     {
  108.         return;
  109.     }
  110.  
  111.     @Override
  112.     public void onBypassFeedback(L2PcInstance player, String command)
  113.     {
  114.         if(player == null)
  115.             return;
  116.  
  117.         String cmd = command.split(" ")[0];
  118.         if (cmd.equalsIgnoreCase("showset"))
  119.         {
  120.             String buffsetname = command.split(" ")[1];
  121.             showSet(player, buffsetname);
  122.         }
  123.         else if (cmd.equalsIgnoreCase("showpage"))
  124.         {
  125.             String page = command.split(" ")[1];
  126.             if(page.equalsIgnoreCase("main"))
  127.                 showMain(player);
  128.             else if(page.contains("mygroup"))
  129.             {
  130.                 String buffsetname = page.split(";")[1];
  131.                 showSet(player, buffsetname);
  132.             }
  133.             else
  134.                 showMain(player);
  135.         }
  136.         else if (cmd.equalsIgnoreCase("newbuffset"))
  137.         {
  138.             String buffsetname = command.split(" ")[1];
  139.            
  140.             if(!patterns.matcher(buffsetname).matches())
  141.             {
  142.                 showMain(player);
  143.                 player.sendMessage("Error! Incorrect name!");
  144.                 return;
  145.             }          
  146.            
  147.             if(player.getVar("BuffSets") == null)
  148.                 player.setVar("BuffSets", "");
  149.                        
  150.             int c = player.getVar("BuffSets").split(";").length;
  151.             if(c == countGroup)
  152.             {
  153.                 showMain(player);
  154.                 player.sendMessage("Error! Limits groups!");
  155.                 return;
  156.             }
  157.            
  158.             String name = "buffset"+Rnd.get(0, 10000);
  159.             player.setVar("BuffSets", player.getVar("BuffSets")+name+";");         
  160.             player.setVar(name, buffsetname + ";");        
  161.             showSet(player, name);
  162.         }    
  163.         else if (cmd.equalsIgnoreCase("delbuffset"))
  164.         {
  165.             if(player.getVar("BuffSets") == null)
  166.                 player.setVar("BuffSets", "");
  167.            
  168.             if(player.getVar("BuffSets").split(";").length > 0)
  169.             {
  170.                 String buffsetname = command.split(" ")[1];        
  171.                 player.setVar("BuffSets", player.getVar("BuffSets").replaceFirst((buffsetname+";"), ""));              
  172.                 player.unsetVar(buffsetname);
  173.             }
  174.            
  175.             showMain(player);
  176.         }
  177.         else if (cmd.equalsIgnoreCase("buffset"))
  178.         {
  179.             String buffsetname = command.split(" ")[1];
  180.             buffsetAllAndShowPage(player, buffsetname);
  181.             showMain(player);
  182.         }
  183.         else if (cmd.equalsIgnoreCase("showbuffsetadd"))
  184.         {
  185.             String buffsetname = command.split(" ")[1];
  186.             String htm = HtmCache.getInstance().getHtm("data/html/NpcBuffer/mygroupedit.htm");
  187.             NpcHtmlMessage page = new NpcHtmlMessage(getObjectId());           
  188.             page.setHtml(htm);
  189.             page.replace("%objectId%", String.valueOf(getObjectId()));
  190.             page.replace("%setName%", buffsetname);
  191.             player.sendPacket(page);
  192.             player.sendPacket(ActionFailed.STATIC_PACKET);
  193.         }
  194.         else if (cmd.equalsIgnoreCase("buffsetadd"))
  195.         {
  196.             String skillId = command.split(" ")[1].split(";")[0];
  197.             String skillLvl = command.split(" ")[1].split(";")[1];
  198.             String buffsetname = command.split(" ")[1].split(";")[2];
  199.            
  200.             if(player.getVar(buffsetname).split(";").length >= maxCountBuffSelfGroup + 1)
  201.             {
  202.                 player.sendMessage("Error! Max slot buffs!");
  203.             }
  204.             else
  205.             {
  206.                 player.setVar(buffsetname, (player.getVar(buffsetname) + skillId + "," + skillLvl + ";"));
  207.             }
  208.             showSet(player, buffsetname);
  209.         }
  210.         else if (cmd.equalsIgnoreCase("buffsetdel"))
  211.         {
  212.             String skillId = command.split(" ")[1].split(";")[0];
  213.             String skillLvl = command.split(" ")[1].split(";")[1];
  214.             String buffsetname = command.split(" ")[1].split(";")[2];
  215.            
  216.             player.setVar(buffsetname, player.getVar(buffsetname).replaceFirst(skillId + "," + skillLvl + ";", ""));
  217.             showSet(player, buffsetname);
  218.         }      
  219.         else if(cmd.equalsIgnoreCase("statbuff"))
  220.         {
  221.             String[] params = command.split(" ")[1].split(";");
  222.             buffOne(player, params[0], params[1]);
  223.             showMain(player);
  224.         }
  225.         else if (command.equalsIgnoreCase("cancel"))
  226.         {
  227.             if(priceСancel < 0)
  228.                 return;
  229.            
  230.             if (player.getAdena() < priceСancel)
  231.             {
  232.                 player.sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
  233.                 return;
  234.             }
  235.             if (!checkConditions(player))
  236.             {
  237.                 player.sendPacket(ActionFailed.STATIC_PACKET);
  238.                 return;
  239.             }
  240.             player.reduceAdena("L2Buffer", priceСancel, player, true);
  241.             L2Summon summon = player.getPet();
  242.             if (summon != null && summon == player.getTarget())
  243.             {
  244.                summon.stopAllEffects();
  245.             }
  246.             else
  247.             {            
  248.                 player.stopAllEffects();
  249.             }
  250.         }
  251.         else if (command.equalsIgnoreCase("heal"))
  252.         {
  253.             if(priceHeal < 0)
  254.                 return;
  255.            
  256.             if (player.getAdena() < priceHeal)
  257.             {
  258.                 player.sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
  259.                 return;
  260.             }
  261.             if (!checkConditions(player))
  262.             {
  263.                 player.sendPacket(ActionFailed.STATIC_PACKET);
  264.                 return;
  265.             }
  266.             player.reduceAdena("L2Buffer", priceHeal, player, true);
  267.             L2Summon summon = player.getPet();
  268.             if (summon != null && summon == player.getTarget())
  269.             {
  270.                summon.setCurrentHpMp(summon.getMaxHp(), summon.getMaxMp());
  271.             }
  272.             else
  273.             {            
  274.                 player.setCurrentHpMp(player.getMaxHp(), player.getMaxMp());
  275.             }
  276.         }
  277.     }
  278.    
  279.     public void showMain(L2PcInstance activeChar)
  280.     {
  281.         String htm = HtmCache.getInstance().getHtm("data/html/NpcBuffer/main.htm");
  282.         NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  283.         html.setHtml(htm);
  284.         html.replace("%objectId%", String.valueOf(getObjectId()));      
  285.        
  286.         StringBuilder sb = new StringBuilder();
  287.         int c = activeChar.getVar("BuffSets") == null ? 0 : activeChar.getVar("BuffSets").split(";").length;
  288.         if(c > 0)
  289.         {
  290.             sb.append("<table width=280>");
  291.             for (String name : activeChar.getVar("BuffSets").split(";"))
  292.             {
  293.                 if (activeChar.getVar(name) != null)
  294.                 {
  295.                     String buffsetname = activeChar.getVar(name);
  296.                     sb.append("<tr>");
  297.                     sb.append("<td align=\"right\"><button value=\"Buff\" action=\"bypass -h npc_").append(getObjectId()).append("_buffset ").append(name).append("\" width=\"60\" height=\"21\" back=\"L2UI_CH3.bigbutton_down\" fore=\"L2UI_CH3.bigbutton\"></td>");
  298.                     sb.append("<td align=\"center\"><button value=\"").append(buffsetname.substring(0, buffsetname.indexOf(";"))).append("\" action=\"bypass -h npc_").append(getObjectId()).append("_showset ").append(name).append("\" width=\"80\" height=\"21\" back=\"L2UI_CH3.bigbutton_down\" fore=\"L2UI_CH3.bigbutton\"></td>");
  299.                     sb.append("<td align=\"left\"><button value=\"Remove\" action=\"bypass -h npc_").append(getObjectId()).append("_delbuffset ").append(name).append("\" width=\"60\" height=\"21\" back=\"L2UI_CH3.bigbutton_down\" fore=\"L2UI_CH3.bigbutton\"></td>");
  300.                     sb.append("</tr>");
  301.                 }
  302.             }
  303.             sb.append("</table>");
  304.         }
  305.        
  306.         html.replace("%mybuffsets%", sb.toString());
  307.         activeChar.sendPacket(html);
  308.         activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  309.     }
  310.  
  311.     @SuppressWarnings("SleepWhileHoldingLock")
  312.     public void buffsetAllAndShowPage(L2PcInstance activeChar, String command)
  313.     {
  314.         StringTokenizer st = new StringTokenizer(activeChar.getVar(command), ";");
  315.  
  316.         if (activeChar.getAdena() < (priceBuff * (st.countTokens() - 1)))
  317.         {
  318.             activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
  319.             return;
  320.         }
  321.  
  322.         if (!checkConditions(activeChar))
  323.         {
  324.             activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  325.             return;
  326.         }
  327.  
  328.         activeChar.reduceAdena("L2Buffer", priceBuff * (st.countTokens() - 1), activeChar, true);
  329.  
  330.         st.nextToken();
  331.         while(st.hasMoreTokens())
  332.         {
  333.             String[] skillst = st.nextToken().split(",");
  334.             int skillId = Integer.valueOf(skillst[0]);
  335.             int skillLvl = Integer.valueOf(skillst[1]);
  336.             if (contains(skillId, skillLvl))
  337.             {
  338.                 L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLvl);
  339.                 L2Summon summon = activeChar.getPet();
  340.                 if (summon != null && summon == activeChar.getTarget())
  341.                 {
  342.                     skill.getEffects(activeChar, summon, buffTime);
  343.                 }
  344.                 else
  345.                 {
  346.                     skill.getEffects(activeChar, activeChar, buffTime);
  347.                 }
  348.                 try
  349.                 {
  350.                     Thread.sleep(100);
  351.                 }
  352.                 catch (InterruptedException ex)
  353.                 {
  354.                 }
  355.             }
  356.         }
  357.         activeChar.updateEffectIcons();
  358.         activeChar.refreshOverloaded();
  359.         showSet(activeChar, command);
  360.     }
  361.  
  362.     public void showSet(L2PcInstance activeChar, String command)
  363.     {
  364.         StringTokenizer st = new StringTokenizer(activeChar.getVar(command), ";");
  365.         String htm = HtmCache.getInstance().getHtm("data/html/NpcBuffer/mygroupview.htm");
  366.         NpcHtmlMessage page = new NpcHtmlMessage(getObjectId());           
  367.         page.setHtml(htm);
  368.         page.replace("%objectId%", String.valueOf(getObjectId()));
  369.         page.replace("%groupName%", st.nextToken());
  370.         page.replace("%setName%", command);
  371.  
  372.         StringBuilder sb = new StringBuilder();
  373.         int i = 0;
  374.         int m = 0;
  375.        
  376.         sb.append("<table width=\"280\"><tr>");
  377.  
  378.         while (st.hasMoreTokens())
  379.         {
  380.             String[] skillst = st.nextToken().split(",");
  381.             int skillId = Integer.valueOf(skillst[0]);
  382.             int skillLvl = Integer.valueOf(skillst[1]);
  383.             if (!contains(skillId, skillLvl))
  384.             {
  385.                 activeChar.setVar(command, activeChar.getVar(command).replaceFirst(skillId + "," + skillLvl + ";", ""));
  386.                 continue;
  387.             }
  388.             i++;
  389.             m++;
  390.             if (m == 2)
  391.             {
  392.                 m = 0;
  393.                 sb.append("</tr><tr>");
  394.             }
  395.             L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLvl);
  396.             if(skill != null)
  397.                 sb.append("<td width=\"140\"><a action=\"bypass -h npc_").append(getObjectId()).append("_buffsetdel ").append(skill.getId()).append(";").append(skill.getLevel()).append(";").append(command).append("\">").append(skill.getName()).append("</a></td>");
  398.         }
  399.         sb.append("</tr></table>");
  400.        
  401.         if (i == 0)
  402.         {
  403.             sb.append("<center>Add buffs, you can click on 'Add'</center>");
  404.         }
  405.  
  406.         page.replace("%mybuffsets%", sb.toString());
  407.         activeChar.sendPacket(page);
  408.         activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  409.     }
  410.     public void buffOne(L2PcInstance activeChar, String skillId, String skillLvl)
  411.     {
  412.  
  413.         if (activeChar.getAdena() < priceBuff)
  414.         {
  415.             activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
  416.             return;
  417.         }
  418.  
  419.         if (!checkConditions(activeChar))
  420.         {
  421.             activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  422.             return;
  423.         }
  424.  
  425.         try
  426.         {
  427.             int skill_id = Integer.valueOf(skillId);
  428.             int lvl = Integer.valueOf(skillLvl);
  429.             if (contains(skill_id, lvl))
  430.             {
  431.                 activeChar.reduceAdena("L2Buffer", priceBuff, activeChar, true);
  432.                 L2Skill skill = SkillTable.getInstance().getInfo(skill_id, lvl);
  433.                 L2Summon summon = activeChar.getPet();
  434.                 if (summon != null && summon == activeChar.getTarget())
  435.                 {
  436.                     skill.getEffects(activeChar, summon, buffTime);
  437.                 }
  438.                 else
  439.                 {
  440.                     skill.getEffects(activeChar, activeChar, buffTime);
  441.                 }
  442.             }
  443.         }
  444.         catch (Exception e)
  445.         {
  446.             activeChar.sendMessage("Invalid skill!");
  447.         }
  448.     }
  449.  
  450.     private boolean checkConditions(L2PcInstance player)
  451.     {
  452.         if (player.isDead() || player.isAlikeDead())
  453.         {
  454.             return false;
  455.         }    
  456.         return true;
  457.     }
  458.  
  459.     private static boolean contains(int skillId, int lvl)
  460.     {
  461.        for(int[] grp : groupStaticBuff)
  462.        {
  463.            if(grp[0] == skillId && grp[1] == lvl)
  464.                return true;
  465.        }
  466.        return false;
  467.     }
  468.    
  469.    
  470.     public static void main(String[] args)
  471.     {
  472.  
  473.     }
  474. }
Advertisement
Add Comment
Please, Sign In to add comment