05-21-2012, 03:00 PM
здравствуйте уважаемые, вот переписываю стандартного баффера от l2rt.
В баффере есть проблемма, заходишь в любой раздел, бафаешь бафф и тебя возвращает на основное окно баффера, не очень удобно.
Пожалуйста помогите это убрать.
В баффере есть проблемма, заходишь в любой раздел, бафаешь бафф и тебя возвращает на основное окно баффера, не очень удобно.
Пожалуйста помогите это убрать.
код
PHP код:
<?php
package npc.model;
import java.util.regex.Pattern;
import net.sf.l2j.Config;
import net.sf.l2j.gameserver.model.actor.instance.L2NpcIn stance;
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.L2PcIns tance;
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;
/**
* @descr L2Buffer
* @author Koten [RusTeam]
*/
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,3}, //Empower
{1040,3}, //Shield
{1036,2}, //Magic Barrier
{1388,3}, //Greater Might
{1243,6}, //Bless Shield
{1268,4}, //Vampiric Rage
{1078,6}, //Concentration
{1045,6}, //Blessed Body
{1077,3}, //Focus
{1240,3}, //Guidance
{1085,3}, //Acumen
{1389,3}, //Greater Shield
{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; // цена 1го баффа
private static final int priceСancel = 20000; // цена канцела эффектов на персонаже (-1 отключить)
private static final int priceHeal = 20000; // цена лечения персонажа (-1 отключить)
private static final int buffTime = 7200; // 1 час
private static final int maxCountBuffSelfGroup = 36; //максимальное количество баффов в своей группе
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;
}
showPage(player, "main");
}
@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"))
showPage(player, "main");
else if(page.contains("mygroup"))
{
String buffsetname = page.split(";")[1];
showSet(player, buffsetname);
}
else
showPage(player, page);
}
else if (cmd.equalsIgnoreCase("newbuffset")) // новый набор баффов
{
String buffsetname = command.split(" ")[1];
if(!patterns.matcher(buffsetname).matches())
{
showPage(player, "main");
player.sendMessage("Error! Incorrect name!");
return;
}
if(player.getVar("BuffSets") == null)
player.setVar("BuffSets", "");
int c = player.getVar("BuffSets").split(";").length;
if(c == countGroup)
{
showPage(player, "main");
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((buffsetnam e+";"), ""));
player.unsetVar(buffsetname);
}
showPage(player, "main");
}
else if (cmd.equalsIgnoreCase("buffset")) // использовать свою группу баффов
{
String buffsetname = command.split(" ")[1];
buffsetAllAndShowPage(player, buffsetname);
showPage(player, "main");
}
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]);
showPage(player, "main");
}
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 showPage(L2PcInstance activeChar, String page)
{
String htm = HtmCache.getInstance().getHtm("data/html/NpcBuffer/" + page + ".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=\"Баффать\" 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=\"Удалить\" 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
{
try
{
skill.getEffects(activeChar, activeChar, buffTime);
}
catch (Exception e)
{
e.getStackTrace();
continue;
}
}
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>Добавить баффы можно нажав кнопку 'Добавить'</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)
{
}
}