12-09-2011, 09:06 PM
есть маза сделать его быстрее?
бафает год
бафает год
Код:
есть маза сделать его быстрее?
бафает год
[QUOTE]package services.NPCBuffer;
import l2p.Config;
import l2p.common.ThreadPoolManager;
import l2p.extensions.multilang.CustomMessage;
import l2p.extensions.scripts.Functions;
import l2p.gameserver.cache.Msg;
import l2p.gameserver.instancemanager.TownManager;
import l2p.gameserver.model.L2Character;
import l2p.gameserver.model.L2Player;
import l2p.gameserver.model.L2Skill;
import l2p.gameserver.model.L2Summon;
import l2p.gameserver.model.entity.residence.Residence;
import l2p.gameserver.model.entity.siege.Siege;
import l2p.gameserver.model.instances.L2NpcInstance;
import l2p.gameserver.serverpackets.MagicSkillLaunched;
import l2p.gameserver.serverpackets.MagicSkillUse;
import l2p.gameserver.tables.SkillTable;
import l2p.util.Files;
import l2p.util.Util;
public class Buffer extends Functions
{
/** Количество бафов в группах */
private static int grpCount1, grpCount2, grpCount3, grpCount4, grpCount5;
// Количество бафов в 1 и второй группах должно быть одинаковое
// ?????????? ????? ? 1 ? ?????? ??????? ?????? ???? ??????????
private static int buffs[][] = { // id, lvl, group
// Chants
{ 1251, 2, 5 }, // Chant of Fury
{ 1252, 3, 5 }, // Chant of Evasion
{ 1253, 3, 5 }, // Chant of Rage
{ 1284, 3, 5 }, // Chant of Revenge
{ 1308, 3, 5 }, // Chant of Predator
{ 1309, 3, 5 }, // Chant of Eagle
{ 1310, 4, 5 }, // Chant of Vampire
{ 1362, 1, 5 }, // Chant of Spirit
{ 1363, 1, 5 }, // Chant of Victory
{ 1390, 3, 5 }, // War Chant
{ 1391, 3, 5 }, // Earth Chant
// Songs
{ 264, 1, 4 }, // Song of Earth
{ 265, 1, 4 }, // Song of Life
{ 266, 1, 4 }, // Song of Water
{ 267, 1, 4 }, // Song of Warding
{ 268, 1, 4 }, // Song of Wind
{ 269, 1, 4 }, // Song of Hunter
{ 270, 1, 4 }, // Song of Invocation
{ 304, 1, 4 }, // Song of Vitality
{ 305, 1, 4 }, // Song of Vengeance
{ 306, 1, 4 }, // Song of Flame Guard
{ 308, 1, 4 }, // Song of Storm Guard
{ 349, 1, 4 }, // Song of Renewal
{ 363, 1, 4 }, // Song of Meditation
{ 364, 1, 4 }, // Song of Champion
// Dances
{ 271, 1, 3 }, // Dance of Warrior
{ 272, 1, 3 }, // Dance of Inspiration
{ 273, 1, 3 }, // Dance of Mystic
{ 274, 1, 3 }, // Dance of Fire
{ 275, 1, 3 }, // Dance of Fury
{ 276, 1, 3 }, // Dance of Concentration
{ 277, 1, 3 }, // Dance of Light
{ 307, 1, 3 }, // Dance of Aqua Guard
{ 309, 1, 3 }, // Dance of Earth Guard
{ 310, 1, 3 }, // Dance of Vampire
{ 311, 1, 3 }, // Dance of Protection
{ 365, 1, 3 }, // Dance of Siren
// ?????? ??? ????? 2
{ 7059, 1, 2 }, // Wild Magic
{ 4356, 3, 2 }, // Empower
{ 4355, 3, 2 }, // Acumen
{ 4352, 1, 2 }, // Berserker Spirit
{ 4346, 4, 2 }, // Mental Shield
{ 4344, 3, 2 }, // Shield
{ 4351, 6, 2 }, // Concentration
{ 4342, 2, 2 }, // Wind Walk
{ 4347, 6, 2 }, // Bless the Body
{ 4348, 6, 2 }, // Bless the Soul
{ 4350, 4, 2 }, // Resist Shock
{ 4347, 6, 2 }, // Bless the Body
{ 4348, 6, 2 }, // Bless the Soul
{ 4349, 2, 2 }, // Magic Barrier
{ 1391, 3, 2 }, // Earth Chant
{ 1252, 3, 2 }, // Chant of Evasion
{ 1284, 3, 2 }, // Chant of Revenge
{ 1362, 1, 2 }, // Chant of Spirit
{ 1413, 1, 2 }, // Chant of Victory
{ 273, 1, 2 }, // Dance of Mystic
{ 276, 1, 2 }, // Dance of Concentration
{ 365, 1, 2 }, // Dance of Siren
{ 264, 1, 2 }, // Song of Earth
{ 266, 1, 2 }, // Song of Water
{ 267, 1, 2 }, // Song of Warding
{ 268, 1, 2 }, // Song of Wind
{ 304, 1, 2 }, // Song of Vitality
{ 306, 1, 2 }, // Song of Flame Guard
{ 308, 1, 2 }, // Song of Storm Guard
{ 349, 1, 2 }, // Song of Renewal
{ 363, 1, 2 }, // Song of Meditation
// ?????? ??? ??????
{ 4345, 3, 1 }, // Might
{ 4344, 3, 1 }, // Shield
{ 4349, 2, 1 }, // Magic Barrier
{ 4342, 2, 1 }, // Wind Walk
{ 4357, 2, 1 }, // Haste
{ 4359, 3, 1 }, // Focus
{ 4358, 3, 1 }, // Guidance
{ 4360, 3, 1 }, // Death Whisper
{ 4354, 4, 1 }, // Vampiric Rage
{ 4346, 4, 1 }, // Mental Shield
{ 4352, 1, 1 }, // Berserker Spirit
{ 4350, 4, 1 }, // Resist Shock
{ 4347, 6, 1 }, // Bless the Body
{ 4348, 6, 1 }, // Bless the Soul
{ 1391, 3, 1 }, // Earth Chant
{ 1252, 3, 1 }, // Chant of Evasion
{ 1284, 3, 1 }, // Chant of Revenge
{ 1362, 1, 1 }, // Chant of Spirit
{ 1363, 1, 1 }, // Chant of Victory
{ 271, 1, 1 }, // Dance of Warrior
{ 274, 1, 1 }, // Dance of Fire
{ 275, 1, 1 }, // Dance of Fury
{ 264, 1, 1 }, // Song of Earth
{ 267, 1, 1 }, // Song of Warding
{ 268, 1, 1 }, // Song of Wind
{ 269, 1, 1 }, // Song of Hunter
{ 304, 1, 1 }, // Song of Vitality
{ 306, 1, 1 }, // Song of Flame Guard
{ 308, 1, 1 }, // Song of Storm Guard
{ 349, 1, 1 }, // Song of Renewal
{ 364, 1, 1 } // Song of Champion
};
public static void onLoad()
{
if(Config.SERVICES_BUFFER_ENABLED)
System.out.println("Loaded Service: NPCBuffer [state: activated]");
else
System.out.println("Loaded Service: NPCBuffer [state: deactivated]");
for(int buff[] : buffs)
switch(buff[2])
{
case 1:
grpCount1++;
break;
case 2:
grpCount2++;
break;
case 3:
grpCount3++;
break;
case 4:
grpCount4++;
break;
case 5:
grpCount5++;
break;
}
}
/**
* Бафает группу баффов, снимает плату за бафф, отображает диалог с кнопкой возврата к списку бафов
* @param args массив строк, где элемент 0 - id группы бафов
*/
public void doBuffGroup(String[] args)
{
L2Player player = (L2Player) getSelf();
L2Summon pet = player.getPet();
L2NpcInstance npc = getNpc();
if(!checkCondition(player, npc))
return;
if(player.getAdena() < Config.SERVICES_BUFFER_PRICE * (Integer.valueOf(args[1]) + 2))
{
player.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
return;
}
player.reduceAdena(Config.SERVICES_BUFFER_PRICE * (Integer.valueOf(args[1]) + 2), true);
int time = 0;
int id_groups = Integer.valueOf(args[0]);
int select_id = Integer.valueOf(args[1]);
L2Skill skill;
for(int buff[] : buffs)
if(buff[2] == id_groups)
{
if(select_id == 0)
{
skill = SkillTable.getInstance().getInfo(buff[0], buff[1]);
time += skill.getHitTime();
ThreadPoolManager.getInstance().scheduleGeneral(new BeginBuff(getNpc(), skill, player), time);
time += 200;
}
if(select_id == 1)
{
if(pet == null)
return;
skill = SkillTable.getInstance().getInfo(buff[0], buff[1]);
time += skill.getHitTime();
ThreadPoolManager.getInstance().scheduleGeneral(new BeginPetBuff(getNpc(), skill, pet), time);
time += 200;
}
}
}
/**
* Бафает один бафф, снимает плату за бафф, отображает диалог с кнопкой возврата к списку бафов
* @param args массив строк: элемент 0 - id скида, элемент 1 - уровень скила
*/
public void doBuff(String[] args)
{
L2Player player = (L2Player) getSelf();
L2Summon pet = player.getPet();
L2NpcInstance npc = getNpc();
if(!checkCondition(player, npc))
return;
if(player.getAdena() < Config.SERVICES_BUFFER_PRICE)
{
player.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
return;
}
try
{
int skill_id = Integer.valueOf(args[0]);
int skill_lvl = Integer.valueOf(args[1]);
int select_id = Integer.valueOf(args[2]);
L2Skill skill = SkillTable.getInstance().getInfo(skill_id, skill_lvl);
if(select_id == 0)
ThreadPoolManager.getInstance().scheduleGeneral(new BeginBuff(getNpc(), skill, player), skill.getHitTime());
if(select_id == 1)
{
if(pet == null)
return;
ThreadPoolManager.getInstance().scheduleGeneral(new BeginPetBuff(getNpc(), skill, pet), skill.getHitTime());
}
player.reduceAdena(Config.SERVICES_BUFFER_PRICE, true);
}
catch(Exception e)
{
player.sendMessage("Invalid skill!");
}
show(Files.read("data/scripts/services/NPCBuffer/buffs-tolist.htm", player), player, npc);
}
/**
* Проверяет возможность бафа персонажа.<BR>
* В случае невозможности бафа показывает игроку html с ошибкой и возвращает false.
* @param player персонаж
* @return true, если можно бафать персонажа
*/
public boolean checkCondition(L2Player player, L2NpcInstance npc)
{
if(!Config.SERVICES_BUFFER_ENABLED || player == null || npc == null)
return false;
if(!L2NpcInstance.canBypassCheck(player, npc))
return false;
String html;
// Проверяем по уровню
if(player.getLevel() > Config.SERVICES_BUFFER_MAX_LVL || player.getLevel() < Config.SERVICES_BUFFER_MIN_LVL)
{
html = Files.read("data/scripts/services/NPCBuffer/no-lvl.htm", player);
html = html.replace("%min_lvl%", Integer.toString(Config.SERVICES_BUFFER_MIN_LVL));
html = html.replace("%max_lvl%", Integer.toString(Config.SERVICES_BUFFER_MAX_LVL));
show(html, player, npc);
return false;
}
//Можно ли юзать бафера во время осады?
if(!Config.SERVICES_BUFFER_SIEGE)
{
Residence castle = TownManager.getInstance().getClosestTown(getSelf()).getCastle();
Siege siege = castle.getSiege();
if(siege != null)
{
show(Files.read("data/scripts/services/NPCBuffer/no-siege.htm", player), player, npc);
return false;
}
}
return true;
}
/* Выбор меню */
public void SelectMenu(String[] args)
{
int select_menu = Integer.valueOf(args[0]);
L2Player player = (L2Player) getSelf();
L2NpcInstance npc = getNpc();
String html = null;
if(select_menu == 0)
html = Files.read("data/scripts/services/NPCBuffer/buffschar.htm", player);
if(select_menu == 2)
html = Files.read("data/scripts/services/NPCBuffer/dance.htm", player);
if(select_menu == 3)
html = Files.read("data/scripts/services/NPCBuffer/song.htm", player);
if(select_menu == 4)
html = Files.read("data/scripts/services/NPCBuffer/chant.htm", player);
if(select_menu == 5)
html = Files.read("data/scripts/services/NPCBuffer/other.htm", player);
if(select_menu == 1)
{
if(Config.SERVICES_BUFFER_PET_ENABLED != true)
return;
if(player.getPet() == null)
return;
html = Files.read("data/scripts/services/NPCBuffer/buffspet.htm", player);
}
assert html != null;
html = html.replace("%grp_price1%", Util.formatAdena(Config.SERVICES_BUFFER_PRICE * (grpCount1 + 2)));
html = html.replace("%grp_price2%", Util.formatAdena(Config.SERVICES_BUFFER_PRICE * (grpCount2 + 2)));
html = html.replace("%grp_price3%", Util.formatAdena(Config.SERVICES_BUFFER_PRICE * (grpCount3 + 2)));
html = html.replace("%grp_price4%", Util.formatAdena(Config.SERVICES_BUFFER_PRICE * (grpCount4 + 2)));
html = html.replace("%grp_price5%", Util.formatAdena(Config.SERVICES_BUFFER_PRICE * (grpCount5 + 2)));
html = html.replace("%buffs_in_grp1%", Integer.toString(grpCount1));
html = html.replace("%buffs_in_grp2%", Integer.toString(grpCount2));
html = html.replace("%buffs_in_grp3%", Integer.toString(grpCount3));
html = html.replace("%buffs_in_grp4%", Integer.toString(grpCount4));
html = html.replace("%buffs_in_grp5%", Integer.toString(grpCount5));
html = html.replace("%price%", Util.formatAdena(Config.SERVICES_BUFFER_PRICE));
show(html, player, npc);
}
/* Показывает страницу с выбором кого бафать. */
public void SelectBuffs()
{
L2Player player = (L2Player) getSelf();
L2NpcInstance lastNpc = player.getLastNpc();
if(!checkCondition(player, lastNpc))
return;
show(Files.read("data/scripts/services/NPCBuffer/buffs.htm", player), player, lastNpc);
}
/**
* Генерит ссылку, которая в дальнейшем аппендится эвент менеждерам
* @return html код ссылки
*/
public static String OutDia(L2Player player)
{
if(!Config.SERVICES_BUFFER_ENABLED)
return "";
String append = "<br><a action=\"bypass -h scripts_services.NPCBuffer.Buffer:SelectBuffs\">";
append += new CustomMessage("scripts.services.NPCBuffer.Buffer.selectBuffs", player);
append += "</a>";
return append;
}
// Далее идут аппенды диалогов эвент гейткиперам
public static String DialogAppend_31212(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31213(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31214(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31215(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31216(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31217(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31218(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31219(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31220(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31221(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31222(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31223(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31224(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31767(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_32048(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public static String DialogAppend_31768(L2Player player, L2NpcInstance npc, Integer val)
{
if(val != 0)
return "";
return OutDia(player);
}
public class BeginBuff implements Runnable
{
L2Character _buffer;
L2Skill _skill;
L2Player _target;
public BeginBuff(L2Character buffer, L2Skill skill, L2Player target)
{
_buffer = buffer;
_skill = skill;
_target = target;
}
@Override
public void run()
{
if(_target.isInOlympiadMode())
return;
_buffer.broadcastPacket(new MagicSkillUse(_buffer, _target, _skill.getDisplayId(), _skill.getLevel(), _skill.getHitTime(), 0, false));
ThreadPoolManager.getInstance().scheduleGeneral(new EndBuff(_buffer, _skill, _target), _skill.getHitTime());
}
}
public class EndBuff implements Runnable
{
L2Character _buffer;
L2Skill _skill;
L2Player _target;
public EndBuff(L2Character buffer, L2Skill skill, L2Player target)
{
_buffer = buffer;
_skill = skill;
_target = target;
}
@Override
public void run()
{
_skill.getEffects(_buffer, _target, false, false, false);
_buffer.broadcastPacket(new MagicSkillLaunched(_buffer.getObjectId(), _skill.getId(), _skill.getLevel(), _target, _skill.isOffensive()));
}
}
public class BeginPetBuff implements Runnable
{
L2Character _buffer;
L2Skill _skill;
L2Summon _target;
public BeginPetBuff(L2Character buffer, L2Skill skill, L2Summon target)
{
_buffer = buffer;
_skill = skill;
_target = target;
}
@Override
public void run()
{
_buffer.broadcastPacket(new MagicSkillUse(_buffer, _target, _skill.getDisplayId(), _skill.getLevel(), _skill.getHitTime(), 0, false));
ThreadPoolManager.getInstance().scheduleGeneral(new EndPetBuff(_buffer, _skill, _target), _skill.getHitTime());
}
}
public class EndPetBuff implements Runnable
{
L2Character _buffer;
L2Skill _skill;
L2Summon _target;
public EndPetBuff(L2Character buffer, L2Skill skill, L2Summon target)
{
_buffer = buffer;
_skill = skill;
_target = target;
}
@Override
public void run()
{
_skill.getEffects(_buffer, _target, false, false, false);
_buffer.broadcastPacket(new MagicSkillLaunched(_buffer.getObjectId(), _skill.getId(), _skill.getLevel(), _target, _skill.isOffensive()));
}
}
}[/QUOTE]