Advertisement
VANPER

[L2JDev] SchemerBuffer {CODE}

Nov 11th, 2020
1,664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.89 KB | None | 0 0
  1. package l2j.dev.gameserver.model.actor.instance;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.StringTokenizer;
  7.  
  8. import l2j.dev.Config;
  9. import l2j.dev.commons.util.StringUtil;
  10. import l2j.dev.gameserver.datatables.SchemeBufferTable;
  11. import l2j.dev.gameserver.datatables.SkillTable;
  12. import l2j.dev.gameserver.model.Skill;
  13. import l2j.dev.gameserver.model.actor.Creature;
  14. import l2j.dev.gameserver.model.actor.Summon;
  15. import l2j.dev.gameserver.model.actor.templates.NpcTemplate;
  16. import l2j.dev.gameserver.network.serverpackets.NpcHtmlMessage;
  17. import l2j.dev.gameserver.util.Util;
  18.  
  19. public class SchemeBufferInstance extends FolkInstance
  20. {
  21.     private static final int PAGE_LIMIT = 6;
  22.    
  23.     public SchemeBufferInstance(int objectId, NpcTemplate template)
  24.     {
  25.         super(objectId, template);
  26.     }
  27.    
  28.     @Override
  29.     public void onBypassFeedback(PlayerInstance player, String command)
  30.     {
  31.         // Simple hack to use createscheme bypass with a space.
  32.         command = command.replace("createscheme ", "createscheme;");
  33.        
  34.         final StringTokenizer st = new StringTokenizer(command, ";");
  35.         final String currentCommand = st.nextToken();
  36.         if (currentCommand.startsWith("menu"))
  37.         {
  38.             final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  39.             html.setFile(getHtmlPath(getNpcId(), 0));
  40.             html.replace("%objectId%", getObjectId());
  41.             player.sendPacket(html);
  42.         }
  43.        
  44. +       if (command.startsWith("getbuffer"))
  45. +       {
  46. +           String val = command.substring(8);
  47. +           StringTokenizer st1 = new StringTokenizer(val, "_");
  48. +          
  49. +           String a = st1.nextToken();
  50. +           int id = Integer.parseInt(a);
  51. +           String b = st1.nextToken();
  52. +           int lvl = Integer.parseInt(b);
  53. +          
  54. +           Skill skill = SkillTable.getInstance().getInfo(id, lvl);
  55. +           if (skill != null)
  56. +           {
  57. +               skill.getEffects(player, player);
  58. +           }
  59. +           showSubBufferWindow(player);
  60. +          
  61. +       }
  62.        
  63.         else if (currentCommand.startsWith("cleanup"))
  64.        
  65.         {
  66.             player.stopAllEffects();
  67.            
  68.             final Summon summon = player.getPet();
  69.             if (summon != null)
  70.             {
  71.                 summon.stopAllEffects();
  72.             }
  73.            
  74.             final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  75.             html.setFile(getHtmlPath(getNpcId(), 0));
  76.             html.replace("%objectId%", getObjectId());
  77.             player.sendPacket(html);
  78.         }
  79.         else if (currentCommand.startsWith("heal"))
  80.         {
  81.             player.setCurrentHpMp(player.getMaxHp(), player.getMaxMp());
  82.             player.setCurrentCp(player.getMaxCp());
  83.            
  84.             final Summon summon = player.getPet();
  85.             if (summon != null)
  86.             {
  87.                 summon.setCurrentHpMp(summon.getMaxHp(), summon.getMaxMp());
  88.             }
  89.            
  90.             final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  91.             html.setFile(getHtmlPath(getNpcId(), 0));
  92.             html.replace("%objectId%", getObjectId());
  93.             player.sendPacket(html);
  94.         }
  95.         else if (currentCommand.startsWith("support"))
  96.         {
  97.             showGiveBuffsWindow(player);
  98.         }
  99.         else if (currentCommand.startsWith("givebuffs"))
  100.         {
  101.             final String schemeName = st.nextToken();
  102.             final int cost = Integer.parseInt(st.nextToken());
  103.             Creature target = null;
  104.             if (st.hasMoreTokens())
  105.             {
  106.                 final String targetType = st.nextToken();
  107.                 if ((targetType != null) && targetType.equalsIgnoreCase("pet"))
  108.                 {
  109.                     target = player.getPet();
  110.                 }
  111.             }
  112.             else
  113.             {
  114.                 target = player;
  115.             }
  116.            
  117.             if (target == null)
  118.             {
  119.                 player.sendMessage("You don't have a pet.");
  120.             }
  121.             else if ((cost == 0) || player.reduceAdena("NPC Buffer", cost, this, true))
  122.             {
  123.                 for (int skillId : SchemeBufferTable.getInstance().getScheme(player.getObjectId(), schemeName))
  124.                 {
  125.                     SkillTable.getInstance().getSkill(skillId, SchemeBufferTable.getInstance().getAvailableBuff(skillId).getLevel()).getEffects(this, target);
  126.                 }
  127.             }
  128.         }
  129.         else if (currentCommand.startsWith("editschemes"))
  130.         {
  131.             showEditSchemeWindow(player, st.nextToken(), st.nextToken(), Integer.parseInt(st.nextToken()));
  132.         }
  133.         else if (currentCommand.startsWith("skill"))
  134.         {
  135.             final String groupType = st.nextToken();
  136.             final String schemeName = st.nextToken();
  137.             final int skillId = Integer.parseInt(st.nextToken());
  138.             final int page = Integer.parseInt(st.nextToken());
  139.             final List<Integer> skills = SchemeBufferTable.getInstance().getScheme(player.getObjectId(), schemeName);
  140.             if (currentCommand.startsWith("skillselect") && !schemeName.equalsIgnoreCase("none"))
  141.             {
  142.                 if (skills.size() < player.getMaxBuffCount())
  143.                 {
  144.                     skills.add(skillId);
  145.                 }
  146.                 else
  147.                 {
  148.                     player.sendMessage("This scheme has reached the maximum amount of buffs.");
  149.                 }
  150.             }
  151.             else if (currentCommand.startsWith("skillunselect"))
  152.             {
  153.                 skills.remove(Integer.valueOf(skillId));
  154.             }
  155.            
  156.             showEditSchemeWindow(player, groupType, schemeName, page);
  157.         }
  158.         else if (currentCommand.startsWith("createscheme"))
  159.         {
  160.             try
  161.             {
  162.                 final String schemeName = st.nextToken().trim();
  163.                 if (schemeName.length() > 14)
  164.                 {
  165.                     player.sendMessage("Scheme's name must contain up to 14 chars.");
  166.                     return;
  167.                 }
  168.                 // Simple hack to use spaces, dots, commas, minus, plus, exclamations or question marks.
  169.                 if (!Util.isAlphaNumeric(schemeName.replace(" ", "").replace(".", "").replace(",", "").replace("-", "").replace("+", "").replace("!", "").replace("?", "")))
  170.                 {
  171.                     player.sendMessage("Please use plain alphanumeric characters.");
  172.                     return;
  173.                 }
  174.                
  175.                 final Map<String, List<Integer>> schemes = SchemeBufferTable.getInstance().getPlayerSchemes(player.getObjectId());
  176.                 if (schemes != null)
  177.                 {
  178.                     if (schemes.size() == Config.BUFFER_MAX_SCHEMES)
  179.                     {
  180.                         player.sendMessage("Maximum schemes amount is already reached.");
  181.                         return;
  182.                     }
  183.                    
  184.                     if (schemes.containsKey(schemeName))
  185.                     {
  186.                         player.sendMessage("The scheme name already exists.");
  187.                         return;
  188.                     }
  189.                 }
  190.                
  191.                 SchemeBufferTable.getInstance().setScheme(player.getObjectId(), schemeName.trim(), new ArrayList<>());
  192.                 showGiveBuffsWindow(player);
  193.             }
  194.             catch (Exception e)
  195.             {
  196.                 player.sendMessage("Scheme's name must contain up to 14 chars.");
  197.             }
  198.         }
  199.         else if (currentCommand.startsWith("deletescheme"))
  200.         {
  201.             try
  202.             {
  203.                 final String schemeName = st.nextToken();
  204.                 final Map<String, List<Integer>> schemes = SchemeBufferTable.getInstance().getPlayerSchemes(player.getObjectId());
  205.                 if ((schemes != null) && schemes.containsKey(schemeName))
  206.                 {
  207.                     schemes.remove(schemeName);
  208.                 }
  209.             }
  210.             catch (Exception e)
  211.             {
  212.                 player.sendMessage("This scheme name is invalid.");
  213.             }
  214.             showGiveBuffsWindow(player);
  215.         }
  216.        
  217.         super.onBypassFeedback(player, command);
  218.     }
  219.    
  220.     @Override
  221.     public String getHtmlPath(int npcId, int value)
  222.     {
  223.         String filename = "";
  224.         if (value == 0)
  225.         {
  226.             filename = Integer.toString(npcId);
  227.         }
  228.         else
  229.         {
  230.             filename = npcId + "-" + value;
  231.         }
  232.         return "data/html/mods/SchemeBuffer/" + filename + ".htm";
  233.     }
  234.    
  235.     /**
  236.      * Sends an html packet to player with Give Buffs menu info for player and pet, depending on targetType parameter {player, pet}
  237.      * @param player : The player to make checks on.
  238.      */
  239.     private void showGiveBuffsWindow(PlayerInstance player)
  240.     {
  241.         final StringBuilder sb = new StringBuilder(200);
  242.         final Map<String, List<Integer>> schemes = SchemeBufferTable.getInstance().getPlayerSchemes(player.getObjectId());
  243.         if ((schemes == null) || schemes.isEmpty())
  244.         {
  245.             sb.append("<font color=\"LEVEL\">You haven't defined any scheme.</font>");
  246.         }
  247.         else
  248.         {
  249.             for (Map.Entry<String, List<Integer>> scheme : schemes.entrySet())
  250.             {
  251.                 final int cost = getFee(scheme.getValue());
  252.                 StringUtil.append(sb, "<font color=\"LEVEL\">", scheme.getKey(), " [", scheme.getValue().size(), " / ", player.getMaxBuffCount(), "]", ((cost > 0) ? " - cost: " + StringUtil.formatNumber(cost) : ""), "</font><br1>");
  253.                 StringUtil.append(sb, "<a action=\"bypass -h npc_%objectId%_givebuffs;" + scheme.getKey() + ";" + cost + "\">Use on Me</a>&nbsp;|&nbsp;");
  254.                 StringUtil.append(sb, "<a action=\"bypass -h npc_%objectId%_givebuffs;" + scheme.getKey() + ";" + cost + ";pet\">Use on Pet</a>&nbsp;|&nbsp;");
  255.                 StringUtil.append(sb, "<a action=\"bypass -h npc_%objectId%_editschemes;Buffs;" + scheme.getKey() + ";1\">Edit</a>&nbsp;|&nbsp;");
  256.                 StringUtil.append(sb, "<a action=\"bypass -h npc_%objectId%_deletescheme;" + scheme.getKey() + "\">Delete</a><br>");
  257.             }
  258.         }
  259.        
  260.         final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  261.         html.setFile(getHtmlPath(getNpcId(), 1));
  262.         html.replace("%schemes%", sb.toString());
  263.         html.replace("%max_schemes%", Config.BUFFER_MAX_SCHEMES);
  264.         html.replace("%objectId%", getObjectId());
  265.         player.sendPacket(html);
  266.     }
  267.    
  268.     /**
  269.      * This sends an html packet to player with Edit Scheme Menu info. This allows player to edit each created scheme (add/delete skills)
  270.      * @param player : The player to make checks on.
  271.      * @param groupType : The group of skills to select.
  272.      * @param schemeName : The scheme to make check.
  273.      * @param page The page.
  274.      */
  275.     private void showEditSchemeWindow(PlayerInstance player, String groupType, String schemeName, int page)
  276.     {
  277.         final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  278.         final List<Integer> schemeSkills = SchemeBufferTable.getInstance().getScheme(player.getObjectId(), schemeName);
  279.         html.setFile(getHtmlPath(getNpcId(), 2));
  280.         html.replace("%schemename%", schemeName);
  281.         html.replace("%count%", schemeSkills.size() + " / " + player.getMaxBuffCount());
  282.         html.replace("%typesframe%", getTypesFrame(groupType, schemeName));
  283.         html.replace("%skilllistframe%", getGroupSkillList(player, groupType, schemeName, page));
  284.         html.replace("%objectId%", getObjectId());
  285.         player.sendPacket(html);
  286.     }
  287.    
  288.     /**
  289.      * @param player : The player to make checks on.
  290.      * @param groupType : The group of skills to select.
  291.      * @param schemeName : The scheme to make check.
  292.      * @param page The page.
  293.      * @return a String representing skills available to selection for a given groupType.
  294.      */
  295.     private String getGroupSkillList(PlayerInstance player, String groupType, String schemeName, int page)
  296.     {
  297.         // Retrieve the entire skills list based on group type.
  298.         List<Integer> skills = SchemeBufferTable.getInstance().getSkillsIdsByType(groupType);
  299.         if (skills.isEmpty())
  300.         {
  301.             return "That group doesn't contain any skills.";
  302.         }
  303.        
  304.         // Calculate page number.
  305.         final int max = Util.countPagesNumber(skills.size(), PAGE_LIMIT);
  306.         if (page > max)
  307.         {
  308.             page = max;
  309.         }
  310.        
  311.         // Cut skills list up to page number.
  312.         skills = skills.subList((page - 1) * PAGE_LIMIT, Math.min(page * PAGE_LIMIT, skills.size()));
  313.        
  314.         final List<Integer> schemeSkills = SchemeBufferTable.getInstance().getScheme(player.getObjectId(), schemeName);
  315.         final StringBuilder sb = new StringBuilder(skills.size() * 150);
  316.         int row = 0;
  317.         for (int skillId : skills)
  318.         {
  319.             sb.append(((row % 2) == 0 ? "<table width=\"280\" bgcolor=\"000000\"><tr>" : "<table width=\"280\"><tr>"));
  320.             if (skillId < 100)
  321.             {
  322.                 if (schemeSkills.contains(skillId))
  323.                 {
  324.                     StringUtil.append(sb, "<td height=40 width=40><img src=\"icon.skill00", skillId, "\" width=32 height=32></td><td width=190>", SkillTable.getInstance().getSkill(skillId, 1).getName(), "<br1><font color=\"B09878\">", SchemeBufferTable.getInstance().getAvailableBuff(skillId).getDescription(), "</font></td><td><button action=\"bypass -h npc_%objectId%_skillunselect;", groupType, ";", schemeName, ";", skillId, ";", page, "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomout2\" fore=\"L2UI_CH3.mapbutton_zoomout1\"></td>");
  325.                 }
  326.                 else
  327.                 {
  328.                     StringUtil.append(sb, "<td height=40 width=40><img src=\"icon.skill00", skillId, "\" width=32 height=32></td><td width=190>", SkillTable.getInstance().getSkill(skillId, 1).getName(), "<br1><font color=\"B09878\">", SchemeBufferTable.getInstance().getAvailableBuff(skillId).getDescription(), "</font></td><td><button action=\"bypass -h npc_%objectId%_skillselect;", groupType, ";", schemeName, ";", skillId, ";", page, "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomin2\" fore=\"L2UI_CH3.mapbutton_zoomin1\"></td>");
  329.                 }
  330.             }
  331.             else if (skillId < 1000)
  332.             {
  333.                 if (schemeSkills.contains(skillId))
  334.                 {
  335.                     StringUtil.append(sb, "<td height=40 width=40><img src=\"icon.skill0", skillId, "\" width=32 height=32></td><td width=190>", SkillTable.getInstance().getSkill(skillId, 1).getName(), "<br1><font color=\"B09878\">", SchemeBufferTable.getInstance().getAvailableBuff(skillId).getDescription(), "</font></td><td><button action=\"bypass -h npc_%objectId%_skillunselect;", groupType, ";", schemeName, ";", skillId, ";", page, "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomout2\" fore=\"L2UI_CH3.mapbutton_zoomout1\"></td>");
  336.                 }
  337.                 else
  338.                 {
  339.                     StringUtil.append(sb, "<td height=40 width=40><img src=\"icon.skill0", skillId, "\" width=32 height=32></td><td width=190>", SkillTable.getInstance().getSkill(skillId, 1).getName(), "<br1><font color=\"B09878\">", SchemeBufferTable.getInstance().getAvailableBuff(skillId).getDescription(), "</font></td><td><button action=\"bypass -h npc_%objectId%_skillselect;", groupType, ";", schemeName, ";", skillId, ";", page, "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomin2\" fore=\"L2UI_CH3.mapbutton_zoomin1\"></td>");
  340.                 }
  341.             }
  342.             else
  343.             {
  344.                 if (schemeSkills.contains(skillId))
  345.                 {
  346.                     StringUtil.append(sb, "<td height=40 width=40><img src=\"icon.skill", skillId, "\" width=32 height=32></td><td width=190>", SkillTable.getInstance().getSkill(skillId, 1).getName(), "<br1><font color=\"B09878\">", SchemeBufferTable.getInstance().getAvailableBuff(skillId).getDescription(), "</font></td><td><button action=\"bypass -h npc_%objectId%_skillunselect;", groupType, ";", schemeName, ";", skillId, ";", page, "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomout2\" fore=\"L2UI_CH3.mapbutton_zoomout1\"></td>");
  347.                 }
  348.                 else
  349.                 {
  350.                     StringUtil.append(sb, "<td height=40 width=40><img src=\"icon.skill", skillId, "\" width=32 height=32></td><td width=190>", SkillTable.getInstance().getSkill(skillId, 1).getName(), "<br1><font color=\"B09878\">", SchemeBufferTable.getInstance().getAvailableBuff(skillId).getDescription(), "</font></td><td><button action=\"bypass -h npc_%objectId%_skillselect;", groupType, ";", schemeName, ";", skillId, ";", page, "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomin2\" fore=\"L2UI_CH3.mapbutton_zoomin1\"></td>");
  351.                 }
  352.             }
  353.            
  354.             sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=277 height=1>");
  355.             row++;
  356.         }
  357.        
  358.         // Build page footer.
  359.         sb.append("<br><img src=\"L2UI.SquareGray\" width=277 height=1><table width=\"100%\" bgcolor=000000><tr>");
  360.         if (page > 1)
  361.         {
  362.             sb.append("<td align=left width=70><a action=\"bypass -h npc_" + getObjectId() + "_editschemes;" + groupType + ";" + schemeName + ";" + (page - 1) + "\">Previous</a></td>");
  363.         }
  364.         else
  365.         {
  366.             sb.append("<td align=left width=70>Previous</td>");
  367.         }
  368.        
  369.         sb.append("<td align=center width=100>Page " + page + "</td>");
  370.         if (page < max)
  371.         {
  372.             sb.append("<td align=right width=70><a action=\"bypass -h npc_" + getObjectId() + "_editschemes;" + groupType + ";" + schemeName + ";" + (page + 1) + "\">Next</a></td>");
  373.         }
  374.         else
  375.         {
  376.             sb.append("<td align=right width=70>Next</td>");
  377.         }
  378.        
  379.         sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=277 height=1>");
  380.         return sb.toString();
  381.     }
  382.    
  383.     /**
  384.      * @param groupType : The group of skills to select.
  385.      * @param schemeName : The scheme to make check.
  386.      * @return a string representing all groupTypes available. The group currently on selection isn't linkable.
  387.      */
  388.     private static String getTypesFrame(String groupType, String schemeName)
  389.     {
  390.         final StringBuilder sb = new StringBuilder(500);
  391.         sb.append("<table>");
  392.        
  393.         int count = 0;
  394.         for (String type : SchemeBufferTable.getInstance().getSkillTypes())
  395.         {
  396.             if (count == 0)
  397.             {
  398.                 sb.append("<tr>");
  399.             }
  400.            
  401.             if (groupType.equalsIgnoreCase(type))
  402.             {
  403.                 sb.append("<td width=65>" + type + "</td>");
  404.             }
  405.             else
  406.             {
  407.                 sb.append("<td width=65><a action=\"bypass -h npc_%objectId%_editschemes;" + type + ";" + schemeName + ";1\">" + type + "</a></td>");
  408.             }
  409.            
  410.             count++;
  411.             if (count == 4)
  412.             {
  413.                 sb.append("</tr>");
  414.                 count = 0;
  415.             }
  416.         }
  417.        
  418.         if (!sb.toString().endsWith("</tr>"))
  419.         {
  420.             sb.append("</tr>");
  421.         }
  422.        
  423.         sb.append("</table>");
  424.        
  425.         return sb.toString();
  426.     }
  427.    
  428. +   private void showSubBufferWindow(PlayerInstance player)
  429. +   {
  430. +       NpcHtmlMessage html = new NpcHtmlMessage(1);
  431. +      
  432. +       html.setFile(getHtmlPath(getNpcId(), 0));
  433. +       html.replace("%objectId%", getObjectId());
  434. +       player.sendPacket(html);
  435. +   }
  436.    
  437.     /**
  438.      * @param list : A list of skill ids.
  439.      * @return a global fee for all skills contained in list.
  440.      */
  441.     private static int getFee(List<Integer> list)
  442.     {
  443.         if (Config.BUFFER_STATIC_BUFF_COST > 0)
  444.         {
  445.             return list.size() * Config.BUFFER_STATIC_BUFF_COST;
  446.         }
  447.        
  448.         int fee = 0;
  449.         for (int sk : list)
  450.         {
  451.             fee += SchemeBufferTable.getInstance().getAvailableBuff(sk).getPrice();
  452.         }
  453.        
  454.         return fee;
  455.     }
  456. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement