Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package npc.model;
- import java.util.regex.Pattern;
- import net.sf.l2j.Config;
- import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
- import net.sf.l2j.gameserver.templates.L2NpcTemplate;
- import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
- import java.util.StringTokenizer;
- import net.sf.l2j.Config;
- import net.sf.l2j.gameserver.cache.HtmCache;
- import net.sf.l2j.gameserver.datatables.SkillTable;
- import net.sf.l2j.gameserver.model.L2Skill;
- import net.sf.l2j.gameserver.model.L2Summon;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- import net.sf.l2j.gameserver.network.L2GameClient;
- import net.sf.l2j.gameserver.network.SystemMessageId;
- import net.sf.l2j.gameserver.serverpackets.ActionFailed;
- import net.sf.l2j.gameserver.serverpackets.SystemMessage;
- import net.sf.l2j.util.Rnd;
- public class L2BufferInstance extends L2NpcInstance
- {
- private static final Pattern patterns = Pattern.compile("[a-zA-Z0-9]{1,8}");
- private static final int[][] groupStaticBuff = new int[][]
- {
- {1068,3}, //Might
- {1086,2}, //Haste
- {1242,3}, //Death Whisper
- {1062,2}, //Berserker Spirit
- {4401,1}, //Empower
- {1040,3}, //Shield
- {1036,2}, //Magic Barrier
- {1243,6}, //Bless Shield
- {1268,4}, //Vampiric Rage
- {1078,6}, //Concentration
- {1045,6}, //Blessed Body
- {1077,3}, //Focus
- {1270,3}, //Guidance
- {1085,3}, //Acumen
- {1303,2}, //Wild Magic
- {1035,4}, //Mental Shield
- {1304,3}, //Advanced Block
- {1087,3}, //Agility
- {1259,4}, //Resist Shock
- {1204,2}, //Wind Walk
- {1048,6}, //Blessed Soul
- {275,1}, //Fury
- {274,1}, //Fire
- {272,1}, //Inspiration
- {271,1}, //Warrior
- {273,1}, //Mystic
- {365,1}, //Siren
- {276,1}, //Concentration
- {310,1}, //Vampire
- {264,1}, //Earth
- {268,1}, //Wind
- {269,1}, //Hunter
- {304,1}, //Vitality
- {349,1}, //Renewal
- {267,1}, //Warding
- {364,1}, //Champion
- {1413,1}, //Magnus Chant
- {1355,1}, //Pr. of Water
- {1357,1}, //Pr. of Wind
- {1356,1}, //Pr. of Fire
- {1363,1} //Chant of Victory
- };
- private static final int countGroup = 3;
- private static final int priceBuff = 20000;
- private static final int priceСancel = 20000;
- private static final int priceHeal = 20000;
- private static final int buffTime = 3600;
- private static final int maxCountBuffSelfGroup = 28;
- public L2BufferInstance(int objectId, L2NpcTemplate template)
- {
- super(objectId, template);
- }
- @Override
- public void showChatWindow(L2PcInstance player, int val)
- {
- if (player == null || player.isDead())
- {
- return;
- }
- if (player.isCursedWeaponEquiped())
- {
- return;
- }
- showMain(player);
- }
- @Override
- public void onActionShift(L2GameClient client)
- {
- return;
- }
- @Override
- public void onBypassFeedback(L2PcInstance player, String command)
- {
- if(player == null)
- return;
- String cmd = command.split(" ")[0];
- if (cmd.equalsIgnoreCase("showset"))
- {
- String buffsetname = command.split(" ")[1];
- showSet(player, buffsetname);
- }
- else if (cmd.equalsIgnoreCase("showpage"))
- {
- String page = command.split(" ")[1];
- if(page.equalsIgnoreCase("main"))
- showMain(player);
- else if(page.contains("mygroup"))
- {
- String buffsetname = page.split(";")[1];
- showSet(player, buffsetname);
- }
- else
- showMain(player);
- }
- else if (cmd.equalsIgnoreCase("newbuffset"))
- {
- String buffsetname = command.split(" ")[1];
- if(!patterns.matcher(buffsetname).matches())
- {
- showMain(player);
- player.sendMessage("Error! Incorrect name!");
- return;
- }
- if(player.getVar("BuffSets") == null)
- player.setVar("BuffSets", "");
- int c = player.getVar("BuffSets").split(";").length;
- if(c == countGroup)
- {
- showMain(player);
- player.sendMessage("Error! Limits groups!");
- return;
- }
- String name = "buffset"+Rnd.get(0, 10000);
- player.setVar("BuffSets", player.getVar("BuffSets")+name+";");
- player.setVar(name, buffsetname + ";");
- showSet(player, name);
- }
- else if (cmd.equalsIgnoreCase("delbuffset"))
- {
- if(player.getVar("BuffSets") == null)
- player.setVar("BuffSets", "");
- if(player.getVar("BuffSets").split(";").length > 0)
- {
- String buffsetname = command.split(" ")[1];
- player.setVar("BuffSets", player.getVar("BuffSets").replaceFirst((buffsetname+";"), ""));
- player.unsetVar(buffsetname);
- }
- showMain(player);
- }
- else if (cmd.equalsIgnoreCase("buffset"))
- {
- String buffsetname = command.split(" ")[1];
- buffsetAllAndShowPage(player, buffsetname);
- showMain(player);
- }
- else if (cmd.equalsIgnoreCase("showbuffsetadd"))
- {
- String buffsetname = command.split(" ")[1];
- String htm = HtmCache.getInstance().getHtm("data/html/NpcBuffer/mygroupedit.htm");
- NpcHtmlMessage page = new NpcHtmlMessage(getObjectId());
- page.setHtml(htm);
- page.replace("%objectId%", String.valueOf(getObjectId()));
- page.replace("%setName%", buffsetname);
- player.sendPacket(page);
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
- else if (cmd.equalsIgnoreCase("buffsetadd"))
- {
- String skillId = command.split(" ")[1].split(";")[0];
- String skillLvl = command.split(" ")[1].split(";")[1];
- String buffsetname = command.split(" ")[1].split(";")[2];
- if(player.getVar(buffsetname).split(";").length >= maxCountBuffSelfGroup + 1)
- {
- player.sendMessage("Error! Max slot buffs!");
- }
- else
- {
- player.setVar(buffsetname, (player.getVar(buffsetname) + skillId + "," + skillLvl + ";"));
- }
- showSet(player, buffsetname);
- }
- else if (cmd.equalsIgnoreCase("buffsetdel"))
- {
- String skillId = command.split(" ")[1].split(";")[0];
- String skillLvl = command.split(" ")[1].split(";")[1];
- String buffsetname = command.split(" ")[1].split(";")[2];
- player.setVar(buffsetname, player.getVar(buffsetname).replaceFirst(skillId + "," + skillLvl + ";", ""));
- showSet(player, buffsetname);
- }
- else if(cmd.equalsIgnoreCase("statbuff"))
- {
- String[] params = command.split(" ")[1].split(";");
- buffOne(player, params[0], params[1]);
- showMain(player);
- }
- else if (command.equalsIgnoreCase("cancel"))
- {
- if(priceСancel < 0)
- return;
- if (player.getAdena() < priceСancel)
- {
- player.sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
- return;
- }
- if (!checkConditions(player))
- {
- player.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- player.reduceAdena("L2Buffer", priceСancel, player, true);
- L2Summon summon = player.getPet();
- if (summon != null && summon == player.getTarget())
- {
- summon.stopAllEffects();
- }
- else
- {
- player.stopAllEffects();
- }
- }
- else if (command.equalsIgnoreCase("heal"))
- {
- if(priceHeal < 0)
- return;
- if (player.getAdena() < priceHeal)
- {
- player.sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
- return;
- }
- if (!checkConditions(player))
- {
- player.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- player.reduceAdena("L2Buffer", priceHeal, player, true);
- L2Summon summon = player.getPet();
- if (summon != null && summon == player.getTarget())
- {
- summon.setCurrentHpMp(summon.getMaxHp(), summon.getMaxMp());
- }
- else
- {
- player.setCurrentHpMp(player.getMaxHp(), player.getMaxMp());
- }
- }
- }
- public void showMain(L2PcInstance activeChar)
- {
- String htm = HtmCache.getInstance().getHtm("data/html/NpcBuffer/main.htm");
- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- html.setHtml(htm);
- html.replace("%objectId%", String.valueOf(getObjectId()));
- StringBuilder sb = new StringBuilder();
- int c = activeChar.getVar("BuffSets") == null ? 0 : activeChar.getVar("BuffSets").split(";").length;
- if(c > 0)
- {
- sb.append("<table width=280>");
- for (String name : activeChar.getVar("BuffSets").split(";"))
- {
- if (activeChar.getVar(name) != null)
- {
- String buffsetname = activeChar.getVar(name);
- sb.append("<tr>");
- 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>");
- 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>");
- 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>");
- sb.append("</tr>");
- }
- }
- sb.append("</table>");
- }
- html.replace("%mybuffsets%", sb.toString());
- activeChar.sendPacket(html);
- activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- }
- @SuppressWarnings("SleepWhileHoldingLock")
- public void buffsetAllAndShowPage(L2PcInstance activeChar, String command)
- {
- StringTokenizer st = new StringTokenizer(activeChar.getVar(command), ";");
- if (activeChar.getAdena() < (priceBuff * (st.countTokens() - 1)))
- {
- activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
- return;
- }
- if (!checkConditions(activeChar))
- {
- activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- activeChar.reduceAdena("L2Buffer", priceBuff * (st.countTokens() - 1), activeChar, true);
- st.nextToken();
- while(st.hasMoreTokens())
- {
- String[] skillst = st.nextToken().split(",");
- int skillId = Integer.valueOf(skillst[0]);
- int skillLvl = Integer.valueOf(skillst[1]);
- if (contains(skillId, skillLvl))
- {
- L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLvl);
- L2Summon summon = activeChar.getPet();
- if (summon != null && summon == activeChar.getTarget())
- {
- skill.getEffects(activeChar, summon, buffTime);
- }
- else
- {
- skill.getEffects(activeChar, activeChar, buffTime);
- }
- try
- {
- Thread.sleep(100);
- }
- catch (InterruptedException ex)
- {
- }
- }
- }
- activeChar.updateEffectIcons();
- activeChar.refreshOverloaded();
- showSet(activeChar, command);
- }
- public void showSet(L2PcInstance activeChar, String command)
- {
- StringTokenizer st = new StringTokenizer(activeChar.getVar(command), ";");
- String htm = HtmCache.getInstance().getHtm("data/html/NpcBuffer/mygroupview.htm");
- NpcHtmlMessage page = new NpcHtmlMessage(getObjectId());
- page.setHtml(htm);
- page.replace("%objectId%", String.valueOf(getObjectId()));
- page.replace("%groupName%", st.nextToken());
- page.replace("%setName%", command);
- StringBuilder sb = new StringBuilder();
- int i = 0;
- int m = 0;
- sb.append("<table width=\"280\"><tr>");
- while (st.hasMoreTokens())
- {
- String[] skillst = st.nextToken().split(",");
- int skillId = Integer.valueOf(skillst[0]);
- int skillLvl = Integer.valueOf(skillst[1]);
- if (!contains(skillId, skillLvl))
- {
- activeChar.setVar(command, activeChar.getVar(command).replaceFirst(skillId + "," + skillLvl + ";", ""));
- continue;
- }
- i++;
- m++;
- if (m == 2)
- {
- m = 0;
- sb.append("</tr><tr>");
- }
- L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLvl);
- if(skill != null)
- 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>");
- }
- sb.append("</tr></table>");
- if (i == 0)
- {
- sb.append("<center>Add buffs, you can click on 'Add'</center>");
- }
- page.replace("%mybuffsets%", sb.toString());
- activeChar.sendPacket(page);
- activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- }
- public void buffOne(L2PcInstance activeChar, String skillId, String skillLvl)
- {
- if (activeChar.getAdena() < priceBuff)
- {
- activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
- return;
- }
- if (!checkConditions(activeChar))
- {
- activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- try
- {
- int skill_id = Integer.valueOf(skillId);
- int lvl = Integer.valueOf(skillLvl);
- if (contains(skill_id, lvl))
- {
- activeChar.reduceAdena("L2Buffer", priceBuff, activeChar, true);
- L2Skill skill = SkillTable.getInstance().getInfo(skill_id, lvl);
- L2Summon summon = activeChar.getPet();
- if (summon != null && summon == activeChar.getTarget())
- {
- skill.getEffects(activeChar, summon, buffTime);
- }
- else
- {
- skill.getEffects(activeChar, activeChar, buffTime);
- }
- }
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Invalid skill!");
- }
- }
- private boolean checkConditions(L2PcInstance player)
- {
- if (player.isDead() || player.isAlikeDead())
- {
- return false;
- }
- return true;
- }
- private static boolean contains(int skillId, int lvl)
- {
- for(int[] grp : groupStaticBuff)
- {
- if(grp[0] == skillId && grp[1] == lvl)
- return true;
- }
- return false;
- }
- public static void main(String[] args)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment