Немного адаптировал менеджера под L2jLink
Добавлена выдача хиро (надо тестить)
Весь шоп публичный тс. при успешном совершение действия идет анонс типа:
WiseFox сменил ник на *WiseFox*
+Идет всплеск света
Покупка геройства идет по дням (1,10,30)
Скачать можно по ссылке RGHOST
Если чето не пашет отписываем сразу же исправлю
Скрытый текстpackage com.l2jfrozen.gameserver.model.actor.instance;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.regex.Matcher;
import com.l2jfrozen.Config;
import com.l2jfrozen.gameserver.datatables.sql.CharNameTable;
import com.l2jfrozen.gameserver.model.entity.Announcements;
import com.l2jfrozen.gameserver.network.serverpackets.*;
import com.l2jfrozen.util.CloseUtil;
import com.l2jfrozen.util.database.L2DatabaseFactory;
import javolution.text.TextBuilder;
import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
import com.l2jfrozen.gameserver.util.Util;
/**
* Created with IntelliJ IDEA.
* User: AlexMa
* Date: 15.07.12
* Time: 21:22
* To change this template use File | Settings | File Templates.
*/
public class L2CharManagerInstance extends L2FolkInstance {
// Загружаем меню
private final String NPC_MENU = "<html><title>Char Manager</title><body>" +
"<a action=\"bypass -h npc_%objectId%_showwindow 1\">Я хочу сменить ник</a><br>" +
"<a action=\"bypass -h npc_%objectId%_showwindow 2\">Я хочу сменить цвет ника</a><br>" +
"<a action=\"bypass -h npc_%objectId%_showwindow 3\">Я хочу сменить цвет титула</a><br>" +
"<a action=\"bypass -h npc_%objectId%_showwindow 4\">Я хочу получить статус дворянина</a><br>" +
"<a action=\"bypass -h npc_%objectId%_showwindow 5\">Я хочу получить статус героя</a><br>" +
"<a action=\"bypass -h npc_%objectId%_showwindow 6\">Я хочу сменить пол</a><br>" +
"<a action=\"bypass -h npc_%objectId%_showwindow 7\">Я хочу очистить счетчик ПК</a><br>" +
"</body></html>";
// Настройка валюты
private final int CoinID = 4037;
private final String CoinName = "Coin of Luck";
// Ник
private final int CountName = 15;
private final String NickNamePattern = ".*"; // для разрешения спец. символов
// Цвет ника
private final int CountNameColor = 5;
// Цвет титула
private final int CountTitleColor = 5;
// Hero 1 = 1 день, 2 = 10 дней, 3 = 30 дней
private final int CountHero1 = 3, CountHero2 = 15, CountHero3 = 30;
//Nobless
private final int CountNobless = 10;
String INSERT_DATA = "REPLACE INTO characters_custom_data (obj_Id, char_name, hero, noble, hero_end_date) VALUES (?,?,?,?,?)";
// Smena pola
private final int CountSex = 30;
// Nulled PK
private final String CoinNamePK = "Coin of Luck";
private final int CoinIdPK = 4037;
private final int CountPK = 1; // Цена за 1 ПК;1 ПК = 1 COL
public L2CharManagerInstance(int objectId, L2NpcTemplate template) {
super(objectId, template);
}
public void onBypassFeedback(L2PcInstance player, String command)
{
StringTokenizer st = new StringTokenizer(command, " ");
String actualCommand = st.nextToken();
if(actualCommand.startsWith("showwindow"))
{
showWindow(player, Integer.parseInt(st.nextToken()));
}
else if(actualCommand.startsWith("change_nickname"))
{
String name = st.nextToken();
playerSetNickName(player, name);
}
else if(actualCommand.startsWith("change_nickcolor"))
{
playerSetColor(player, st.nextToken(), 1);
}
else if(actualCommand.startsWith("change_titlecolor"))
{
playerSetColor(player, st.nextToken(), 2);
}
else if(actualCommand.startsWith("change_pkcount"))
{
changePkCount(player, Integer.parseInt(st.nextToken()));
}
else if(actualCommand.startsWith("setstatus"))
{
setStatus(player, Integer.parseInt(st.nextToken()));
}
else if(actualCommand.startsWith("sethero"))
{
setHero(player, Integer.parseInt(st.nextToken()));
}
}
public void onAction(L2PcInstance player)
{
player.setLastFolkNPC(this);
if(!canTarget(player))
return;
if(this != player.getTarget())
{
player.setTarget(this);
MyTargetSelected my = new MyTargetSelected(getObjectId(), 0);
player.sendPacket(my);
player.sendPacket(new ValidateLocation(this));
}
else
{
if(!canInteract(player))
{
}
else
{
NpcHtmlMessage html = new NpcHtmlMessage(1);
html.setHtml(NPC_MENU);
sendHtmlMessage(player, html);
}
}
player.sendPacket(ActionFailed.STATIC_PACKET);
}
private void sendHtmlMessage(L2PcInstance player, NpcHtmlMessage html)
{
html.replace("%objectId%", String.valueOf(getObjectId()));
html.replace("%npcId%", String.valueOf(getNpcId()));
player.sendPacket(html);
}
private void playerSetNickName(L2PcInstance player, String name)
{
if (name.length() < 3 || name.length() > 16 || !Util.isAlphaNumeric(name) || !isValidName(name))
{
player.sendMessage("Неправильное имя.");
return;
}
if (player.getInventory().getInventoryItemCount(CoinID, 0) < CountName)
{
player.sendMessage("У Вас не достаточное кол-во монет для проведения операции.");
return;
}
else if (CharNameTable.getInstance().doesCharNameExist(name))
{
player.sendMessage("Это имя уже занято.");
return;
}
else if (player.isClanLeader())
{
player.sendMessage("Передайте клан на время смены ника другому игроку");
return;
}
else
{
if(player.getInventory().getItemByItemId(CoinID) != null && player.getInventory().getItemByItemId(CoinID).getCount() >= CountName)
{
MagicSkillUser MSU = new MagicSkillUser(player, player, 2023, 1, 1, 0);
player.sendPacket(MSU);
player.broadcastPacket(MSU);
Announcements.getInstance().announceToAll(player.getName() + " сменил свой ник на " + name);
player.setName(name);
player.destroyItemByItemId("Consume", CoinID, CountName, player, false);
player.broadcastUserInfo();
player.sendMessage("Ваше ник изменен.");
player.sendMessage("Не заходим в клан до рестарта сервера.");
player.store();
}
else
{
player.sendMessage("Не хватает айтемов");
}
}
}
private void playerSetColor(L2PcInstance player, String color, int type)
{
int colorh = -1;
if(color.equalsIgnoreCase("Green"))
{
colorh = Integer.decode("0x00FF00");
}
else if(color.equalsIgnoreCase("Yellow"))
{
colorh = Integer.decode("0x00FFFF");
}
else if(color.equalsIgnoreCase("Orange"))
{
colorh = Integer.decode("0x0099FF");
}
else if(color.equalsIgnoreCase("Blue"))
{
colorh = Integer.decode("0xFF0000");
}
else if(color.equalsIgnoreCase("Black"))
{
colorh = Integer.decode("0x000000");
}
else if(color.equalsIgnoreCase("White"))
{
colorh = Integer.decode("0xFFFFFF");
}
if(type == 1)
{
if(player.getInventory().getItemByItemId(CoinID) != null && player.getInventory().getItemByItemId(CoinID).getCount() >= CountNameColor && colorh != -1)
{
player.destroyItemByItemId("Consume", CoinID, CountNameColor, player, false);
MagicSkillUser MSU = new MagicSkillUser(player, player, 2023, 1, 1, 0);
player.sendPacket(MSU);
player.broadcastPacket(MSU);
Announcements.getInstance().announceToAll(player.getName() + " сделал себе " + color + " ник !");
player.getAppearance().setNameColor(colorh);
player.broadcastUserInfo();
player.sendMessage("Цвет вашего ника изменен на: " + color);
}
else
{
player.sendMessage("Не хватает айтемов.");
}
}
else if(type == 2)
{
if(player.getInventory().getItemByItemId(CoinID) != null && player.getInventory().getItemByItemId(CoinID).getCount() >= CountTitleColor)
{
player.destroyItemByItemId("Consume", CoinID, CountTitleColor, player, false);
MagicSkillUser MSU = new MagicSkillUser(player, player, 2023, 1, 1, 0);
player.sendPacket(MSU);
player.broadcastPacket(MSU);
Announcements.getInstance().announceToAll(player.getName() + " сделал себе " + color + " титул !");
player.getAppearance().setTitleColor(colorh);
player.broadcastUserInfo();
player.sendMessage("Цвет вашего титула изменен на: " + color);
}
else
{
player.sendMessage("Не хватает айтемов");
}
}
}
private void changePkCount(L2PcInstance player, int count)
{
if(player.getInventory().getItemByItemId(CoinIdPK) != null && player.getInventory().getItemByItemId(CoinIdPK).getCount() >= CountPK * count)
{
int inipkKills = player.getPkKills();
if(inipkKills == 0) {
player.sendMessage("У вас 0 ПК");
return;
}
else if(inipkKills < count)
{
player.sendMessage("Не правильное количество ПК");
return;
}
player.destroyItemByItemId("Consume", CoinIdPK, count * CountPK, player, false);
MagicSkillUser MSU = new MagicSkillUser(player, player, 2023, 1, 1, 0);
player.sendPacket(MSU);
player.broadcastPacket(MSU);
Announcements.getInstance().announceToAll(player.getName() + " удалил " + count + "ПК !");
player.setPkKills(inipkKills - count);
player.sendPacket(new UserInfo(player));
player.sendMessage("У Вас убрано " + count + " PK");
}
else
{
player.sendMessage("Не хватает айтемов");
}
}
private void setStatus(L2PcInstance player, int type)
{
if(type == 1)
{
if(player.isNoble())
{
player.sendMessage("Вы уже дворянин");
return;
}
else if(player.getInventory().getItemByItemId(CoinID) == null || player.getInventory().getItemByItemId(CoinID).getCount() < CountNobless)
{
player.sendMessage("Не хватает айтемов");
return;
}
player.destroyItemByItemId("Consume", CoinID, CountNobless, player, false);
MagicSkillUser MSU = new MagicSkillUser(player, player, 2023, 1, 1, 0);
player.sendPacket(MSU);
player.broadcastPacket(MSU);
Announcements.getInstance().announceToAll(player.getName() + "получил статус дворянина !");
player.setNoble(true);
player.sendMessage("Поздравляем ! Вы получили статус дворянина !");
player.broadcastUserInfo();
player.getInventory().addItem("Noblesse Tiara",7694, 1, player, player.getTarget());
}
else if(type == 2)
{
if(player.getInventory().getItemByItemId(CoinID) == null || player.getInventory().getItemByItemId(CoinID).getCount() < CountSex)
{
player.sendMessage("Не хватает айтемов");
return;
}
player.destroyItemByItemId("Consume", CoinID, CountSex, player, false);
MagicSkillUser MSU = new MagicSkillUser(player, player, 2023, 1, 1, 0);
player.sendPacket(MSU);
player.broadcastPacket(MSU);
Announcements.getInstance().announceToAll(player.getName() + "сменил пол !");
player.getAppearance().setSex(player.getAppearance().getSex() ? false : true);
player.broadcastUserInfo();
player.decayMe();
player.spawnMe(player.getX(), player.getY(), player.getZ());
player.sendMessage("Вы успешно поменяли пол.");
}
}
private void setHero (L2PcInstance player, int type){
if (type == 1 ){
if(player.getInventory().getItemByItemId(CoinID) != null && player.getInventory().getItemByItemId(CoinID).getCount() >= CountHero1)
{
player.sendMessage("Не хватает айтемов");
return;
}
else if(player.isHero())
{
player.sendMessage("Вы уже герой.");
}
else
{
MagicSkillUser MSU = new MagicSkillUser(player, player, 2023, 1, 1, 0);
player.sendPacket(MSU);
player.broadcastPacket(MSU);
Announcements.getInstance().announceToAll(player.getName() + "получил статус герой на 1 днь !");
player.setIsHero(true);
updateDatabase(player, 1 * 24L * 60L * 60L * 1000L);
player.broadcastUserInfo();
player.destroyItemByItemId("Consume", CoinID, CountHero1, player, false);
player.getInventory().addItem("Wings", 6842, 1, player, null);
}
player = null;
}
else if (type == 2 ){
if(player.getInventory().getItemByItemId(CoinID) != null && player.getInventory().getItemByItemId(CoinID).getCount() >= CountHero2)
{
player.sendMessage("Не хватает айтемов");
return;
}
else if(player.isHero())
{
player.sendMessage("Вы уже герой.");
}
else
{
MagicSkillUser MSU = new MagicSkillUser(player, player, 2023, 1, 1, 0);
player.sendPacket(MSU);
player.broadcastPacket(MSU);
Announcements.getInstance().announceToAll(player.getName() + "получил статус герой на 10 дней !");
player.setIsHero(true);
updateDatabase(player, 10 * 24L * 60L * 60L * 1000L);
player.broadcastUserInfo();
player.destroyItemByItemId("Consume", CoinID, CountHero2, player, false);
player.getInventory().addItem("Wings", 6842, 1, player, null);
}
player = null;
}
if (type == 3 ){
if(player.getInventory().getItemByItemId(CoinID) != null && player.getInventory().getItemByItemId(CoinID).getCount() >= CountHero3)
{
player.sendMessage("Не хватает айтемов");
return;
}
else if(player.isHero())
{
player.sendMessage("Вы уже герой.");
}
else
{
MagicSkillUser MSU = new MagicSkillUser(player, player, 2023, 1, 1, 0);
player.sendPacket(MSU);
player.broadcastPacket(MSU);
Announcements.getInstance().announceToAll(player.getName() + "получил статус герой на 30 дней !");
player.setIsHero(true);
updateDatabase(player, 30 * 24L * 60L * 60L * 1000L);
player.broadcastUserInfo();
player.destroyItemByItemId("Consume", CoinID, CountHero3, player, false);
player.getInventory().addItem("Wings", 6842, 1, player, null);
}
player = null;
}
}
private boolean isValidName(String text)
{
boolean result = true;
String test = text;
Pattern pattern;
try
{
pattern = Pattern.compile(NickNamePattern);
}
catch (PatternSyntaxException e)
{
_log.warning("ERROR : Character name pattern of config is wrong!");
pattern = Pattern.compile(".*");
}
Matcher regexp = pattern.matcher(test);
if (!regexp.matches())
result = false;
return result;
}
private void showWindow(L2PcInstance player, int window)
{
TextBuilder tb;
NpcHtmlMessage html;
if(window == 0)
{
html = new NpcHtmlMessage(1);
html.setHtml(NPC_MENU);
sendHtmlMessage(player, html);
}
else if(window == 1)
{
tb = new TextBuilder();
tb.append("<html><title>Смена ника</title>");
tb.append("<body><center>");
tb.append("Введите ник:<br> <edit var=\"name\" width=120 height=15><br>");
tb.append("<a action=\"bypass -h npc_%objectId%_change_nickname $name\">Сменить имя</a><br>");
tb.append("Цена: " + CountName + " <font color=\"LEVEL\">" + CoinName + "</font><br>");
tb.append("<a action=\"bypass -h npc_%objectId%_showwindow 0\">Назад</a><br>");
tb.append("</center></body></html>");
html = new NpcHtmlMessage(1);
html.setHtml(tb.toString());
sendHtmlMessage(player, html);
}
else if(window == 2)
{
tb = new TextBuilder();
tb.append("<html><title>Смена цвета ника</title><body><center>");
tb.append("Хотите выделятся из толпы ? Смените цвет ника !<br>");
tb.append("Выберите цвет:<br> <combobox var=\"scolor\" width=\"100\" List=\"White;Green;Yellow;Orange;Blue;Black\"><br>");
tb.append("<a action=\"bypass -h npc_%objectId%_change_nickcolor $scolor\">Сменить</a>");
tb.append("Цена: " + CountNameColor + " <font color=\"LEVEL\">" + CoinName + "</font><br>");
tb.append("<a action=\"bypass -h npc_%objectId%_showwindow 0\">Назад</a><br>");
tb.append("</center></body></html>");
html = new NpcHtmlMessage(1);
html.setHtml(tb.toString());
sendHtmlMessage(player, html);
}
else if(window == 3)
{
tb = new TextBuilder();
tb.append("<html><title>Смена цвета титула</title><body><center>");
tb.append("Хотите выделятся из толпы ? Смените цвет титула !<br>");
tb.append("Выберите цвет:<br> <combobox var=\"scolor\" width=\"100\" List=\"White;Green;Yellow;Orange;Blue;Black\"><br>");
tb.append("<a action=\"bypass -h npc_%objectId%_change_titlecolor $scolor\">Сменить</a><br>");
tb.append("Цена: " + CountTitleColor + " <font color=\"LEVEL\">" + CoinName + "</font><br>");
tb.append("<a action=\"bypass -h npc_%objectId%_showwindow 0\">Назад</a><br>");
tb.append("</center></body></html>");
html = new NpcHtmlMessage(1);
html.setHtml(tb.toString());
sendHtmlMessage(player, html);
}
else if(window == 4)
{
tb = new TextBuilder();
tb.append("<html><title>Получение статуса дворянина</title><body><center>");
tb.append("Здесь вы можете получить звание дворянина.<br>");
tb.append("<a action=\"bypass -h npc_%objectId%_setstatus 1\">Получить статус дворянина</a>");
tb.append("Цена: " + CountNobless + " <font color=\"LEVEL\">" + CoinName + "</font><br>");
tb.append("<a action=\"bypass -h npc_%objectId%_showwindow 0\">Назад</a><br>");
tb.append("</center></body></html>");
html = new NpcHtmlMessage(1);
html.setHtml(tb.toString());
sendHtmlMessage(player, html);
}
else if(window == 5)
{
tb = new TextBuilder();
tb.append("<html><title>Получение статуса героя</title><body><center>");
tb.append("Здесь вы можете получить статус героя.<br>");
tb.append("<a action=\"bypass -h npc_%objectId%_sethero 1\">Получить статус героя на 1 день</a><br>");
tb.append("<a action=\"bypass -h npc_%objectId%_sethero 2\">Получить статус героя на 10 дней</a><br>");
tb.append("<a action=\"bypass -h npc_%objectId%_sethero 3\">Получить статус героя на 30 дней</a><br>");
tb.append("Цена: " + CountHero1 + " <font color=\"LEVEL\">" + CoinName + "</font><br>");
tb.append("<a action=\"bypass -h npc_%objectId%_showwindow 0\">Назад</a><br>");
tb.append("</center></body></html>");
html = new NpcHtmlMessage(1);
html.setHtml(tb.toString());
sendHtmlMessage(player, html);
}
else if(window == 6)
{
tb = new TextBuilder();
tb.append("<html><title>Смена пола</title><body><center>");
tb.append("Здесь вы можете изменить пол вашего чара.<br>");
tb.append("<a action=\"bypass -h npc_%objectId%_setstatus 2\">Сменить пол</a><br>");
tb.append("Цена: " + CountSex + " <font color=\"LEVEL\">" + CoinName + "</font><br>");
tb.append("<a action=\"bypass -h npc_%objectId%_showwindow 0\">Назад</a><br>");
tb.append("</center></body></html>");
html = new NpcHtmlMessage(1);
html.setHtml(tb.toString());
sendHtmlMessage(player, html);
}
else if(window == 7)
{
tb = new TextBuilder();
tb.append("<html><title>Смытие пк счетчика</title>");
tb.append("<body><center>");
tb.append("<br> Введите количесто пк, которые будут удалены:<br> <edit var=\"pkcount\" width=120 height=15><br>");
tb.append("<a action=\"bypass -h npc_%objectId%_change_pkcount $pkcount\">Изменить</a><br>");
tb.append("1 ПК = " + CountPK + " <font color=\"LEVEL\">" + CoinNamePK + "</font>");
tb.append("<a action=\"bypass -h npc_%objectId%_showwindow 0\">Назад</a><br>");
tb.append("</center></body></html>");
html = new NpcHtmlMessage(1);
html.setHtml(tb.toString());
sendHtmlMessage(player, html);
}
}
private void updateDatabase(L2PcInstance player, long heroTime)
{
Connection con = null;
try
{
if(player == null)
return;
con = L2DatabaseFactory.getInstance().getConnection(false);
PreparedStatement stmt = con.prepareStatement(INSERT_DATA);
stmt.setInt(1, player.getObjectId());
stmt.setString(2, player.getName());
stmt.setInt(3, 1);
stmt.setInt(4, player.isNoble() ? 1 : 0);
stmt.setLong(5, heroTime == 0 ? 0 : System.currentTimeMillis() + heroTime);
stmt.execute();
stmt.close();
stmt = null;
}
catch(Exception e)
{
if(Config.ENABLE_ALL_EXCEPTIONS)
e.printStackTrace();
_log.log(Level.SEVERE, "Error: could not update database: ", e);
}
finally
{
CloseUtil.close(con);
con = null;
}
}
}