Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package l2j.dev.gameserver.model.actor.instance;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.StringTokenizer;
- import l2j.dev.Config;
- import l2j.dev.commons.util.StringUtil;
- import l2j.dev.gameserver.datatables.SchemeBufferTable;
- import l2j.dev.gameserver.datatables.SkillTable;
- import l2j.dev.gameserver.model.Skill;
- import l2j.dev.gameserver.model.actor.Creature;
- import l2j.dev.gameserver.model.actor.Summon;
- import l2j.dev.gameserver.model.actor.templates.NpcTemplate;
- import l2j.dev.gameserver.network.serverpackets.NpcHtmlMessage;
- import l2j.dev.gameserver.util.Util;
- public class SchemeBufferInstance extends FolkInstance
- {
- private static final int PAGE_LIMIT = 6;
- public SchemeBufferInstance(int objectId, NpcTemplate template)
- {
- super(objectId, template);
- }
- @Override
- public void onBypassFeedback(PlayerInstance player, String command)
- {
- // Simple hack to use createscheme bypass with a space.
- command = command.replace("createscheme ", "createscheme;");
- final StringTokenizer st = new StringTokenizer(command, ";");
- final String currentCommand = st.nextToken();
- if (currentCommand.startsWith("menu"))
- {
- final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- html.setFile(getHtmlPath(getNpcId(), 0));
- html.replace("%objectId%", getObjectId());
- player.sendPacket(html);
- }
- + if (command.startsWith("getbuffer"))
- + {
- + String val = command.substring(8);
- + StringTokenizer st1 = new StringTokenizer(val, "_");
- +
- + String a = st1.nextToken();
- + int id = Integer.parseInt(a);
- + String b = st1.nextToken();
- + int lvl = Integer.parseInt(b);
- +
- + Skill skill = SkillTable.getInstance().getInfo(id, lvl);
- + if (skill != null)
- + {
- + skill.getEffects(player, player);
- + }
- + showSubBufferWindow(player);
- +
- + }
- else if (currentCommand.startsWith("cleanup"))
- {
- player.stopAllEffects();
- final Summon summon = player.getPet();
- if (summon != null)
- {
- summon.stopAllEffects();
- }
- final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- html.setFile(getHtmlPath(getNpcId(), 0));
- html.replace("%objectId%", getObjectId());
- player.sendPacket(html);
- }
- else if (currentCommand.startsWith("heal"))
- {
- player.setCurrentHpMp(player.getMaxHp(), player.getMaxMp());
- player.setCurrentCp(player.getMaxCp());
- final Summon summon = player.getPet();
- if (summon != null)
- {
- summon.setCurrentHpMp(summon.getMaxHp(), summon.getMaxMp());
- }
- final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- html.setFile(getHtmlPath(getNpcId(), 0));
- html.replace("%objectId%", getObjectId());
- player.sendPacket(html);
- }
- else if (currentCommand.startsWith("support"))
- {
- showGiveBuffsWindow(player);
- }
- else if (currentCommand.startsWith("givebuffs"))
- {
- final String schemeName = st.nextToken();
- final int cost = Integer.parseInt(st.nextToken());
- Creature target = null;
- if (st.hasMoreTokens())
- {
- final String targetType = st.nextToken();
- if ((targetType != null) && targetType.equalsIgnoreCase("pet"))
- {
- target = player.getPet();
- }
- }
- else
- {
- target = player;
- }
- if (target == null)
- {
- player.sendMessage("You don't have a pet.");
- }
- else if ((cost == 0) || player.reduceAdena("NPC Buffer", cost, this, true))
- {
- for (int skillId : SchemeBufferTable.getInstance().getScheme(player.getObjectId(), schemeName))
- {
- SkillTable.getInstance().getSkill(skillId, SchemeBufferTable.getInstance().getAvailableBuff(skillId).getLevel()).getEffects(this, target);
- }
- }
- }
- else if (currentCommand.startsWith("editschemes"))
- {
- showEditSchemeWindow(player, st.nextToken(), st.nextToken(), Integer.parseInt(st.nextToken()));
- }
- else if (currentCommand.startsWith("skill"))
- {
- final String groupType = st.nextToken();
- final String schemeName = st.nextToken();
- final int skillId = Integer.parseInt(st.nextToken());
- final int page = Integer.parseInt(st.nextToken());
- final List<Integer> skills = SchemeBufferTable.getInstance().getScheme(player.getObjectId(), schemeName);
- if (currentCommand.startsWith("skillselect") && !schemeName.equalsIgnoreCase("none"))
- {
- if (skills.size() < player.getMaxBuffCount())
- {
- skills.add(skillId);
- }
- else
- {
- player.sendMessage("This scheme has reached the maximum amount of buffs.");
- }
- }
- else if (currentCommand.startsWith("skillunselect"))
- {
- skills.remove(Integer.valueOf(skillId));
- }
- showEditSchemeWindow(player, groupType, schemeName, page);
- }
- else if (currentCommand.startsWith("createscheme"))
- {
- try
- {
- final String schemeName = st.nextToken().trim();
- if (schemeName.length() > 14)
- {
- player.sendMessage("Scheme's name must contain up to 14 chars.");
- return;
- }
- // Simple hack to use spaces, dots, commas, minus, plus, exclamations or question marks.
- if (!Util.isAlphaNumeric(schemeName.replace(" ", "").replace(".", "").replace(",", "").replace("-", "").replace("+", "").replace("!", "").replace("?", "")))
- {
- player.sendMessage("Please use plain alphanumeric characters.");
- return;
- }
- final Map<String, List<Integer>> schemes = SchemeBufferTable.getInstance().getPlayerSchemes(player.getObjectId());
- if (schemes != null)
- {
- if (schemes.size() == Config.BUFFER_MAX_SCHEMES)
- {
- player.sendMessage("Maximum schemes amount is already reached.");
- return;
- }
- if (schemes.containsKey(schemeName))
- {
- player.sendMessage("The scheme name already exists.");
- return;
- }
- }
- SchemeBufferTable.getInstance().setScheme(player.getObjectId(), schemeName.trim(), new ArrayList<>());
- showGiveBuffsWindow(player);
- }
- catch (Exception e)
- {
- player.sendMessage("Scheme's name must contain up to 14 chars.");
- }
- }
- else if (currentCommand.startsWith("deletescheme"))
- {
- try
- {
- final String schemeName = st.nextToken();
- final Map<String, List<Integer>> schemes = SchemeBufferTable.getInstance().getPlayerSchemes(player.getObjectId());
- if ((schemes != null) && schemes.containsKey(schemeName))
- {
- schemes.remove(schemeName);
- }
- }
- catch (Exception e)
- {
- player.sendMessage("This scheme name is invalid.");
- }
- showGiveBuffsWindow(player);
- }
- super.onBypassFeedback(player, command);
- }
- @Override
- public String getHtmlPath(int npcId, int value)
- {
- String filename = "";
- if (value == 0)
- {
- filename = Integer.toString(npcId);
- }
- else
- {
- filename = npcId + "-" + value;
- }
- return "data/html/mods/SchemeBuffer/" + filename + ".htm";
- }
- /**
- * Sends an html packet to player with Give Buffs menu info for player and pet, depending on targetType parameter {player, pet}
- * @param player : The player to make checks on.
- */
- private void showGiveBuffsWindow(PlayerInstance player)
- {
- final StringBuilder sb = new StringBuilder(200);
- final Map<String, List<Integer>> schemes = SchemeBufferTable.getInstance().getPlayerSchemes(player.getObjectId());
- if ((schemes == null) || schemes.isEmpty())
- {
- sb.append("<font color=\"LEVEL\">You haven't defined any scheme.</font>");
- }
- else
- {
- for (Map.Entry<String, List<Integer>> scheme : schemes.entrySet())
- {
- final int cost = getFee(scheme.getValue());
- StringUtil.append(sb, "<font color=\"LEVEL\">", scheme.getKey(), " [", scheme.getValue().size(), " / ", player.getMaxBuffCount(), "]", ((cost > 0) ? " - cost: " + StringUtil.formatNumber(cost) : ""), "</font><br1>");
- StringUtil.append(sb, "<a action=\"bypass -h npc_%objectId%_givebuffs;" + scheme.getKey() + ";" + cost + "\">Use on Me</a> | ");
- StringUtil.append(sb, "<a action=\"bypass -h npc_%objectId%_givebuffs;" + scheme.getKey() + ";" + cost + ";pet\">Use on Pet</a> | ");
- StringUtil.append(sb, "<a action=\"bypass -h npc_%objectId%_editschemes;Buffs;" + scheme.getKey() + ";1\">Edit</a> | ");
- StringUtil.append(sb, "<a action=\"bypass -h npc_%objectId%_deletescheme;" + scheme.getKey() + "\">Delete</a><br>");
- }
- }
- final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- html.setFile(getHtmlPath(getNpcId(), 1));
- html.replace("%schemes%", sb.toString());
- html.replace("%max_schemes%", Config.BUFFER_MAX_SCHEMES);
- html.replace("%objectId%", getObjectId());
- player.sendPacket(html);
- }
- /**
- * This sends an html packet to player with Edit Scheme Menu info. This allows player to edit each created scheme (add/delete skills)
- * @param player : The player to make checks on.
- * @param groupType : The group of skills to select.
- * @param schemeName : The scheme to make check.
- * @param page The page.
- */
- private void showEditSchemeWindow(PlayerInstance player, String groupType, String schemeName, int page)
- {
- final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- final List<Integer> schemeSkills = SchemeBufferTable.getInstance().getScheme(player.getObjectId(), schemeName);
- html.setFile(getHtmlPath(getNpcId(), 2));
- html.replace("%schemename%", schemeName);
- html.replace("%count%", schemeSkills.size() + " / " + player.getMaxBuffCount());
- html.replace("%typesframe%", getTypesFrame(groupType, schemeName));
- html.replace("%skilllistframe%", getGroupSkillList(player, groupType, schemeName, page));
- html.replace("%objectId%", getObjectId());
- player.sendPacket(html);
- }
- /**
- * @param player : The player to make checks on.
- * @param groupType : The group of skills to select.
- * @param schemeName : The scheme to make check.
- * @param page The page.
- * @return a String representing skills available to selection for a given groupType.
- */
- private String getGroupSkillList(PlayerInstance player, String groupType, String schemeName, int page)
- {
- // Retrieve the entire skills list based on group type.
- List<Integer> skills = SchemeBufferTable.getInstance().getSkillsIdsByType(groupType);
- if (skills.isEmpty())
- {
- return "That group doesn't contain any skills.";
- }
- // Calculate page number.
- final int max = Util.countPagesNumber(skills.size(), PAGE_LIMIT);
- if (page > max)
- {
- page = max;
- }
- // Cut skills list up to page number.
- skills = skills.subList((page - 1) * PAGE_LIMIT, Math.min(page * PAGE_LIMIT, skills.size()));
- final List<Integer> schemeSkills = SchemeBufferTable.getInstance().getScheme(player.getObjectId(), schemeName);
- final StringBuilder sb = new StringBuilder(skills.size() * 150);
- int row = 0;
- for (int skillId : skills)
- {
- sb.append(((row % 2) == 0 ? "<table width=\"280\" bgcolor=\"000000\"><tr>" : "<table width=\"280\"><tr>"));
- if (skillId < 100)
- {
- if (schemeSkills.contains(skillId))
- {
- 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>");
- }
- else
- {
- 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>");
- }
- }
- else if (skillId < 1000)
- {
- if (schemeSkills.contains(skillId))
- {
- 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>");
- }
- else
- {
- 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>");
- }
- }
- else
- {
- if (schemeSkills.contains(skillId))
- {
- 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>");
- }
- else
- {
- 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>");
- }
- }
- sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=277 height=1>");
- row++;
- }
- // Build page footer.
- sb.append("<br><img src=\"L2UI.SquareGray\" width=277 height=1><table width=\"100%\" bgcolor=000000><tr>");
- if (page > 1)
- {
- sb.append("<td align=left width=70><a action=\"bypass -h npc_" + getObjectId() + "_editschemes;" + groupType + ";" + schemeName + ";" + (page - 1) + "\">Previous</a></td>");
- }
- else
- {
- sb.append("<td align=left width=70>Previous</td>");
- }
- sb.append("<td align=center width=100>Page " + page + "</td>");
- if (page < max)
- {
- sb.append("<td align=right width=70><a action=\"bypass -h npc_" + getObjectId() + "_editschemes;" + groupType + ";" + schemeName + ";" + (page + 1) + "\">Next</a></td>");
- }
- else
- {
- sb.append("<td align=right width=70>Next</td>");
- }
- sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=277 height=1>");
- return sb.toString();
- }
- /**
- * @param groupType : The group of skills to select.
- * @param schemeName : The scheme to make check.
- * @return a string representing all groupTypes available. The group currently on selection isn't linkable.
- */
- private static String getTypesFrame(String groupType, String schemeName)
- {
- final StringBuilder sb = new StringBuilder(500);
- sb.append("<table>");
- int count = 0;
- for (String type : SchemeBufferTable.getInstance().getSkillTypes())
- {
- if (count == 0)
- {
- sb.append("<tr>");
- }
- if (groupType.equalsIgnoreCase(type))
- {
- sb.append("<td width=65>" + type + "</td>");
- }
- else
- {
- sb.append("<td width=65><a action=\"bypass -h npc_%objectId%_editschemes;" + type + ";" + schemeName + ";1\">" + type + "</a></td>");
- }
- count++;
- if (count == 4)
- {
- sb.append("</tr>");
- count = 0;
- }
- }
- if (!sb.toString().endsWith("</tr>"))
- {
- sb.append("</tr>");
- }
- sb.append("</table>");
- return sb.toString();
- }
- + private void showSubBufferWindow(PlayerInstance player)
- + {
- + NpcHtmlMessage html = new NpcHtmlMessage(1);
- +
- + html.setFile(getHtmlPath(getNpcId(), 0));
- + html.replace("%objectId%", getObjectId());
- + player.sendPacket(html);
- + }
- /**
- * @param list : A list of skill ids.
- * @return a global fee for all skills contained in list.
- */
- private static int getFee(List<Integer> list)
- {
- if (Config.BUFFER_STATIC_BUFF_COST > 0)
- {
- return list.size() * Config.BUFFER_STATIC_BUFF_COST;
- }
- int fee = 0;
- for (int sk : list)
- {
- fee += SchemeBufferTable.getInstance().getAvailableBuff(sk).getPrice();
- }
- return fee;
- }
- }
Add Comment
Please, Sign In to add comment