/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * http://www.gnu.org/copyleft/gpl.html */ package net.sf.l2j.gameserver.handler.admincommandhandlers; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; import javolution.text.TextBuilder; import javolution.util.FastList; import javolution.util.FastMap; import net.sf.l2j.Config; import net.sf.l2j.L2DatabaseFactory; import net.sf.l2j.gameserver.cache.HtmCache; import net.sf.l2j.gameserver.datatables.ItemTable; import net.sf.l2j.gameserver.datatables.NpcTable; import net.sf.l2j.gameserver.datatables.SkillTable; import net.sf.l2j.gameserver.datatables.TradeListTable; import net.sf.l2j.gameserver.handler.IAdminCommandHandler; import net.sf.l2j.gameserver.model.L2DropCategory; import net.sf.l2j.gameserver.model.L2DropData; import net.sf.l2j.gameserver.model.L2ItemInstance; import net.sf.l2j.gameserver.model.L2Object; import net.sf.l2j.gameserver.model.L2Skill; import net.sf.l2j.gameserver.model.L2TradeList; import net.sf.l2j.gameserver.model.actor.instance.L2BoxInstance; import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage; import net.sf.l2j.gameserver.serverpackets.SystemMessage; import net.sf.l2j.gameserver.templates.L2Item; import net.sf.l2j.gameserver.templates.L2NpcTemplate; import net.sf.l2j.gameserver.templates.StatsSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * @author terry * * Window - Preferences - Java - Code Style - Code Templates */ public class AdminEditNpc implements IAdminCommandHandler { private final static Log _log = LogFactory.getLog(AdminEditNpc.class.getName()); private final static int PAGE_LIMIT = 7; private static String[] _adminCommands = { "admin_edit_npc", "admin_save_npc", "admin_show_droplist", "admin_edit_drop", "admin_add_drop", "admin_del_drop", "admin_show_skilllist_npc", // L2J_JP ADD "admin_edit_skill_npc", // L2J_JP ADD "admin_add_skill_npc", // L2J_JP ADD "admin_del_skill_npc", // L2J_JP ADD "admin_showShop", "admin_showShopList", "admin_addShopItem", "admin_delShopItem", "admin_box_access", "admin_editShopItem", "admin_close_window" }; private static final int REQUIRED_LEVEL = Config.GM_NPC_EDIT; private static final int REQUIRED_LEVEL2 = Config.GM_NPC_VIEW; public boolean useAdminCommand(String command, L2PcInstance activeChar) { if (!Config.ALT_PRIVILEGES_ADMIN) if (!((checkLevel(activeChar.getAccessLevel()) || checkLevel2(activeChar.getAccessLevel())) && activeChar.isGM())) return false; else if (command.startsWith("admin_showShop ")) { String[] args = command.split(" "); if (args.length > 1) showShop(activeChar, Integer.parseInt(command.split(" ")[1])); } else if(command.startsWith("admin_showShopList ")) { String[] args = command.split(" "); if (args.length > 2) showShopList(activeChar, Integer.parseInt(command.split(" ")[1]), Integer.parseInt(command.split(" ")[2])); } else if(command.startsWith("admin_edit_npc ")) { try { String[] commandSplit = command.split(" "); int npcId = Integer.valueOf(commandSplit[1]); L2NpcTemplate npc = NpcTable.getInstance().getTemplate(npcId); Show_Npc_Property(activeChar, npc); } catch (Exception e) { activeChar.sendMessage("Wrong usage: //edit_npc "); } } else if(command.startsWith("admin_show_droplist ")) { int npcId = 0; try { npcId = Integer.parseInt(command.substring(20).trim()); } catch(Exception e){} if(npcId > 0) { showNpcDropList(activeChar, npcId); } else { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//show_droplist "); activeChar.sendPacket(sm); } } else if (!Config.ALT_PRIVILEGES_ADMIN && !(checkLevel(activeChar.getAccessLevel()) && activeChar.isGM())) return false; else if(command.startsWith("admin_addShopItem ")) { String[] args = command.split(" "); if (args.length > 1) addShopItem(activeChar, args); } else if(command.startsWith("admin_delShopItem ")) { String[] args = command.split(" "); if (args.length > 2) delShopItem(activeChar, args); } else if(command.startsWith("admin_editShopItem ")) { String[] args = command.split(" "); if (args.length > 2) editShopItem(activeChar, args); } else if(command.startsWith("admin_save_npc ")) { //System.out.println("- " + command); try { save_npc_property(activeChar, command); } catch (StringIndexOutOfBoundsException e) { } } else if(command.startsWith("admin_show_skilllist_npc ")) // L2J_JP ADD { StringTokenizer st = new StringTokenizer(command.substring(25), " "); try { int npcId = -1; int page = 0; if(st.countTokens() <= 2) { if (st.hasMoreTokens()) npcId = Integer.parseInt(st.nextToken()); if (st.hasMoreTokens()) page = Integer.parseInt(st.nextToken()); } if(npcId > 0) { showNpcSkillList(activeChar, npcId, page); } else { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//show_skilllist_npc "); activeChar.sendPacket(sm); } } catch (Exception e) { // Case of wrong monster data SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//show_skilllist_npc "); activeChar.sendPacket(sm); } } else if(command.startsWith("admin_edit_skill_npc ")) // L2J_JP ADD { int npcId = -1, skillId = -1; try { StringTokenizer st = new StringTokenizer(command.substring(21).trim(), " "); if(st.countTokens() == 2) { try { npcId = Integer.parseInt(st.nextToken()); skillId = Integer.parseInt(st.nextToken()); showNpcSkillEdit(activeChar, npcId, skillId); } catch(Exception e) {} } else if(st.countTokens() == 3) { try { npcId = Integer.parseInt(st.nextToken()); skillId = Integer.parseInt(st.nextToken()); int level = Integer.parseInt(st.nextToken()); updateNpcSkillData(activeChar, npcId, skillId, level); } catch(Exception e) { _log.warn("admin_edit_skill_npc parements error: " + command); } } else { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//edit_skill_npc []"); activeChar.sendPacket(sm); } } catch (StringIndexOutOfBoundsException e) { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//edit_skill_npc []"); activeChar.sendPacket(sm); } } else if(command.startsWith("admin_add_skill_npc ")) // L2J_JP ADD { int npcId = -1, skillId = -1; try { StringTokenizer st = new StringTokenizer(command.substring(20).trim(), " "); if(st.countTokens() == 1) { try { String[] input = command.substring(20).split(" "); if (input.length < 1) return true; npcId = Integer.parseInt(input[0]); } catch(Exception e){} if(npcId > 0) { L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId); showNpcSkillAdd(activeChar, npcData); } } else if(st.countTokens() == 3) { try { npcId = Integer.parseInt(st.nextToken()); skillId = Integer.parseInt(st.nextToken()); int level = Integer.parseInt(st.nextToken()); addNpcSkillData(activeChar, npcId, skillId, level); } catch(Exception e) { _log.warn("admin_add_skill_npc parements error: " + command); } } else { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//add_skill_npc []"); activeChar.sendPacket(sm); } } catch (StringIndexOutOfBoundsException e) { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//add_skill_npc []"); activeChar.sendPacket(sm); } } else if(command.startsWith("admin_del_skill_npc ")) // [L2J_JP ADD] { int npcId = -1, skillId = -1; try { String[] input = command.substring(20).split(" "); if (input.length >= 2) { npcId = Integer.parseInt(input[0]); skillId = Integer.parseInt(input[1]); } } catch(Exception e){} if(npcId > 0) { deleteNpcSkillData(activeChar, npcId, skillId); } else { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//del_skill_npc "); activeChar.sendPacket(sm); } } else if(command.startsWith("admin_edit_drop ")) { int npcId = -1, itemId = 0, category = -1000; try { StringTokenizer st = new StringTokenizer(command.substring(16).trim()); if(st.countTokens() == 3) { try { npcId = Integer.parseInt(st.nextToken()); itemId = Integer.parseInt(st.nextToken()); category = Integer.parseInt(st.nextToken()); showEditDropData(activeChar, npcId, itemId, category); } catch(Exception e) {} } else if(st.countTokens() == 6) { try { npcId = Integer.parseInt(st.nextToken()); itemId = Integer.parseInt(st.nextToken()); category = Integer.parseInt(st.nextToken()); int min = Integer.parseInt(st.nextToken()); int max = Integer.parseInt(st.nextToken()); int chance = Integer.parseInt(st.nextToken()); updateDropData(activeChar, npcId, itemId, min, max, category, chance); } catch(Exception e) { _log.warn("admin_edit_drop parements error: " + command); } } else { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//edit_drop [ ]"); activeChar.sendPacket(sm); } } catch (StringIndexOutOfBoundsException e) { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//edit_drop [ ]"); activeChar.sendPacket(sm); } } else if(command.startsWith("admin_add_drop ")) { int npcId = -1; try { StringTokenizer st = new StringTokenizer(command.substring(15).trim()); if(st.countTokens() == 1) { try { String[] input = command.substring(15).split(" "); if (input.length < 1) return true; npcId = Integer.parseInt(input[0]); } catch(Exception e){} if(npcId > 0) { L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId); showAddDropData(activeChar, npcData); } } else if(st.countTokens() == 6) { try { npcId = Integer.parseInt(st.nextToken()); int itemId = Integer.parseInt(st.nextToken()); int category = Integer.parseInt(st.nextToken()); int min = Integer.parseInt(st.nextToken()); int max = Integer.parseInt(st.nextToken()); int chance = Integer.parseInt(st.nextToken()); addDropData(activeChar, npcId, itemId, min, max, category, chance); } catch(Exception e) { _log.warn("admin_add_drop parements error: " + command); } } else { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//add_drop [ ]"); activeChar.sendPacket(sm); } } catch (StringIndexOutOfBoundsException e) { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//add_drop [ ]"); activeChar.sendPacket(sm); } } else if(command.startsWith("admin_del_drop ")) { int npcId = -1, itemId = -1, category = -1000; try { String[] input = command.substring(15).split(" "); if (input.length >= 3) { npcId = Integer.parseInt(input[0]); itemId = Integer.parseInt(input[1]); category = Integer.parseInt(input[2]); } } catch(Exception e){} if(npcId > 0) { deleteDropData(activeChar, npcId, itemId, category); } else { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Command error:"); sm.addString("//del_drop "); activeChar.sendPacket(sm); } } else if(command.startsWith("admin_box_access")) { L2Object target = activeChar.getTarget(); String[] players = command.split(" "); if (target instanceof L2BoxInstance) { L2BoxInstance box = (L2BoxInstance) target; if (players.length > 1) { boolean access = true; for (int i = 1; i < players.length; i++) { if (players[i].equals("no")) { access = false; continue; } box.grantAccess(players[i],access); } } else { try { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); String msg = "Access:"; for (Object p : box.getAccess()) msg += " "+(String)p; sm.addString(msg); activeChar.sendPacket(sm); } catch (Exception e) { _log.info("box_access: "+e); } } } } return true; } private void editShopItem(L2PcInstance admin, String[] args) { int tradeListID = Integer.parseInt(args[1]); int itemID = Integer.parseInt(args[2]); L2TradeList tradeList = TradeListTable.getInstance().getBuyList(tradeListID); L2Item item = ItemTable.getInstance().getTemplate(itemID); if (tradeList.getPriceForItemId(itemID) < 0) { return; } if (args.length > 3) { int price = Integer.parseInt(args[3]); int order = findOrderTradeList(itemID, tradeList.getPriceForItemId(itemID), tradeListID); tradeList.replaceItem(itemID, Integer.parseInt(args[3])); updateTradeList(itemID, price, tradeListID, order); admin.sendMessage("Updated price for "+item.getName()+" in Trade List "+tradeListID); showShopList(admin, tradeListID, 1); return; } NpcHtmlMessage adminReply = new NpcHtmlMessage(5); TextBuilder replyMSG = new TextBuilder(); replyMSG.append("Merchant Shop Item Edit"); replyMSG.append(""); replyMSG.append("
Edit an entry in merchantList."); replyMSG.append("
Editing Item: "+item.getName()); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
PropertyEdit FieldOld Value

Price"+tradeList.getPriceForItemId(itemID)+"
"); replyMSG.append("



"); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } private void delShopItem(L2PcInstance admin, String[] args) { int tradeListID = Integer.parseInt(args[1]); int itemID = Integer.parseInt(args[2]); L2TradeList tradeList = TradeListTable.getInstance().getBuyList(tradeListID); if (tradeList.getPriceForItemId(itemID) < 0) { return; } if (args.length > 3) { int order = findOrderTradeList(itemID, tradeList.getPriceForItemId(itemID), tradeListID); tradeList.removeItem(itemID); deleteTradeList(tradeListID, order); admin.sendMessage("Deleted "+ItemTable.getInstance().getTemplate(itemID).getName()+" from Trade List "+tradeListID); showShopList(admin, tradeListID, 1); return; } NpcHtmlMessage adminReply = new NpcHtmlMessage(5); TextBuilder replyMSG = new TextBuilder(); replyMSG.append("Merchant Shop Item Delete"); replyMSG.append(""); replyMSG.append("
Delete entry in merchantList."); replyMSG.append("
Item to Delete: "+ItemTable.getInstance().getTemplate(itemID).getName()); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
PropertyValue

Price"+tradeList.getPriceForItemId(itemID)+"
"); replyMSG.append("



"); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } private void addShopItem(L2PcInstance admin, String[] args) { int tradeListID = Integer.parseInt(args[1]); L2TradeList tradeList = TradeListTable.getInstance().getBuyList(tradeListID); if (tradeList == null) { admin.sendMessage("TradeList not found!"); return; } if (args.length > 3) { int order = tradeList.getItems().size() + 1; // last item order + 1 int itemID = Integer.parseInt(args[2]); int price = Integer.parseInt(args[3]); L2ItemInstance newItem = ItemTable.getInstance().createDummyItem(itemID); newItem.setPriceToSell(price); tradeList.addItem(newItem); storeTradeList(itemID, price, tradeListID, order); admin.sendMessage("Added "+newItem.getItem().getName()+" to Trade List "+tradeList.getListId()); showShopList(admin, tradeListID, 1); return; } NpcHtmlMessage adminReply = new NpcHtmlMessage(5); TextBuilder replyMSG = new TextBuilder(); replyMSG.append("Merchant Shop Item Add"); replyMSG.append(""); replyMSG.append("
Add a new entry in merchantList."); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
PropertyEdit Field

ItemID
Price
"); replyMSG.append("



"); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } private void showShopList(L2PcInstance admin, int tradeListID, int page) { L2TradeList tradeList = TradeListTable.getInstance().getBuyList(tradeListID); if (page > tradeList.getItems().size() / PAGE_LIMIT + 1 || page < 1) return; NpcHtmlMessage adminReply = new NpcHtmlMessage(5); TextBuilder html = itemListHtml(tradeList, page); adminReply.setHtml(html.toString()); admin.sendPacket(adminReply); } private TextBuilder itemListHtml(L2TradeList tradeList, int page) { TextBuilder replyMSG = new TextBuilder(); replyMSG.append("Merchant Shop List Page: "+page+""); replyMSG.append(""); replyMSG.append("
Edit, add or delete entries in a merchantList."); replyMSG.append(""); replyMSG.append(""); int start = ((page-1) * PAGE_LIMIT); int end = Math.min(((page-1) * PAGE_LIMIT) + (PAGE_LIMIT-1), tradeList.getItems().size() - 1); //System.out.println(end); for (L2ItemInstance item : tradeList.getItems(start, end+1)) { replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); }//*/ replyMSG.append(""); int min = 1; int max = tradeList.getItems().size() / PAGE_LIMIT + 1; if (page > 1) { replyMSG.append(""); } if (page < max) { if (page <= min) replyMSG.append(""); replyMSG.append(""); } replyMSG.append(""); replyMSG.append("
Item NamePriceDelete
"+item.getItem().getName()+""+item.getPriceToSell()+"
.
"); replyMSG.append("
"); replyMSG.append("
"); return replyMSG; } private void showShop(L2PcInstance admin, int merchantID) { List tradeLists = getTradeLists(merchantID); if(tradeLists == null) { admin.sendMessage("Unknown npc template ID" + merchantID); return ; } NpcHtmlMessage adminReply = new NpcHtmlMessage(5); TextBuilder replyMSG = new TextBuilder("Merchant Shop Lists"); replyMSG.append(""); replyMSG.append("
Select a list to view"); replyMSG.append(""); replyMSG.append(""); for (L2TradeList tradeList : tradeLists) { if (tradeList != null) replyMSG.append(""); } replyMSG.append("
Mecrchant List ID
Trade List "+tradeList.getListId()+"
"); replyMSG.append("
"); replyMSG.append("
"); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } private void storeTradeList(int itemID, int price, int tradeListID, int order) { java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement stmt = con.prepareStatement("INSERT INTO merchant_buylists values ("+itemID+","+price+","+tradeListID+","+order+")"); stmt.execute(); stmt.close(); }catch (SQLException esql) {esql.printStackTrace();} } private void updateTradeList(int itemID, int price, int tradeListID, int order) { java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement stmt = con.prepareStatement("UPDATE merchant_buylists SET `price`='"+price+"' WHERE `shop_id`='"+tradeListID+"' AND `order`='"+order+"'"); stmt.execute(); stmt.close(); }catch (SQLException esql) {esql.printStackTrace();} } private void deleteTradeList(int tradeListID, int order) { java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement stmt = con.prepareStatement("DELETE FROM merchant_buylists WHERE `shop_id`='"+tradeListID+"' AND `order`='"+order+"'"); stmt.execute(); stmt.close(); }catch (SQLException esql) {esql.printStackTrace();} } private int findOrderTradeList(int itemID, int price, int tradeListID) { java.sql.Connection con = null; int order = 0; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement stmt = con.prepareStatement("SELECT * FROM merchant_buylists WHERE `shop_id`='"+tradeListID+"' AND `item_id` ='"+itemID+"' AND `price` = '"+price+"'"); ResultSet rs = stmt.executeQuery(); rs.first(); return rs.getInt("order"); }catch (SQLException esql) {esql.printStackTrace();} finally{ try {con.close();} catch (SQLException e) {e.printStackTrace();}} return order; } private List getTradeLists(int merchantID) { String target = "npc_%objectId%_Buy"; String content = HtmCache.getInstance().getHtm("data/html/merchant/"+merchantID+".htm"); if (content == null) { content = HtmCache.getInstance().getHtm("data/html/merchant/7001.htm"); if (content == null) return null; } List tradeLists = new FastList(); String[] lines = content.split("\n"); int pos = 0; for (String line : lines) { pos = line.indexOf(target); if (pos >= 0) { int tradeListID = Integer.decode((line.substring(pos+target.length()+1)).split("\"")[0]); //System.out.println(tradeListID); tradeLists.add(TradeListTable.getInstance().getBuyList(tradeListID)); } } return tradeLists; } private boolean checkLevel(int level) { return (level >= REQUIRED_LEVEL); } private boolean checkLevel2(int level) { return (level >= REQUIRED_LEVEL2); } public String[] getAdminCommandList() { return _adminCommands; } private void Show_Npc_Property(L2PcInstance adminPlayer, L2NpcTemplate npc) { NpcHtmlMessage adminReply = new NpcHtmlMessage(5); String content = HtmCache.getInstance().getHtm("data/html/admin/editnpc.htm"); if (content != null) { adminReply.setHtml(content); adminReply.replace("%npcId%", String.valueOf(npc.npcId)); adminReply.replace("%templateId%", String.valueOf(npc.idTemplate)); adminReply.replace("%name%", npc.name); adminReply.replace("%serverSideName%", npc.serverSideName == true ? "1" : "0"); adminReply.replace("%title%", npc.title); adminReply.replace("%serverSideTitle%", npc.serverSideTitle == true ? "1" : "0"); adminReply.replace("%collisionRadius%", String.valueOf(npc.collisionRadius)); adminReply.replace("%collisionHeight%", String.valueOf(npc.collisionHeight)); adminReply.replace("%level%", String.valueOf(npc.level)); adminReply.replace("%sex%", String.valueOf(npc.sex)); adminReply.replace("%type%", String.valueOf(npc.type)); adminReply.replace("%attackRange%", String.valueOf(npc.baseAtkRange)); adminReply.replace("%hp%", String.valueOf(npc.baseHpMax)); adminReply.replace("%mp%", String.valueOf(npc.baseMpMax)); adminReply.replace("%hpRegen%", String.valueOf(npc.baseHpReg)); adminReply.replace("%mpRegen%", String.valueOf(npc.baseMpReg)); adminReply.replace("%str%", String.valueOf(npc.baseSTR)); adminReply.replace("%con%", String.valueOf(npc.baseCON)); adminReply.replace("%dex%", String.valueOf(npc.baseDEX)); adminReply.replace("%int%", String.valueOf(npc.baseINT)); adminReply.replace("%wit%", String.valueOf(npc.baseWIT)); adminReply.replace("%men%", String.valueOf(npc.baseMEN)); adminReply.replace("%exp%", String.valueOf(npc.rewardExp)); adminReply.replace("%sp%", String.valueOf(npc.rewardSp)); adminReply.replace("%pAtk%", String.valueOf(npc.basePAtk)); adminReply.replace("%pDef%", String.valueOf(npc.basePDef)); adminReply.replace("%mAtk%", String.valueOf(npc.baseMAtk)); adminReply.replace("%mDef%", String.valueOf(npc.baseMDef)); adminReply.replace("%pAtkSpd%", String.valueOf(npc.basePAtkSpd)); adminReply.replace("%aggro%", String.valueOf(npc.aggroRange)); adminReply.replace("%mAtkSpd%", String.valueOf(npc.baseMAtkSpd)); adminReply.replace("%rHand%", String.valueOf(npc.rhand)); adminReply.replace("%lHhand%", String.valueOf(npc.lhand)); adminReply.replace("%armor%", String.valueOf(npc.armor)); adminReply.replace("%walkSpd%", String.valueOf(npc.baseRunSpd * 0.7)); adminReply.replace("%runSpd%", String.valueOf(npc.baseRunSpd)); adminReply.replace("%factionId%", npc.factionId == null ? "" : npc.factionId); adminReply.replace("%factionRange%", String.valueOf(npc.factionRange)); adminReply.replace("%isUndead%", npc.isUndead ? "1" : "0"); adminReply.replace("%absorbLevel%", String.valueOf(npc.absorb_level)); } else adminReply.setHtml("File not found: data/html/admin/editnpc.htm"); adminPlayer.sendPacket(adminReply); } private void save_npc_property(L2PcInstance adminPlayer, String command) { String[] commandSplit = command.split(" "); if (commandSplit.length < 4) return; StatsSet newNpcData = new StatsSet(); try { newNpcData.set("npcId", commandSplit[1]); String statToSet = commandSplit[2]; String value = commandSplit[3]; if (commandSplit.length > 4) { for (int i=0;i 12 ? 0 : intVal); } } catch (Exception e) { _log.warn("Error saving new npc value: " + e); } NpcTable.getInstance().saveNpc(newNpcData); int npcId = newNpcData.getInteger("npcId"); NpcTable.getInstance().reloadNpc(npcId); Show_Npc_Property(adminPlayer, NpcTable.getInstance().getTemplate(npcId)); } private void showNpcDropList(L2PcInstance admin, int npcId) { L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId); if(npcData == null) { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("unknown npc template id" + npcId); admin.sendPacket(sm); return ; } NpcHtmlMessage adminReply = new NpcHtmlMessage(5); TextBuilder replyMSG = new TextBuilder("NPC: "+ npcData.name + "("+npcData.npcId+") 's drop manage"); replyMSG.append(""); replyMSG.append("
Notes: click[drop_id]to show the detail of drop data,click[del] to delete the drop data!"); replyMSG.append(""); replyMSG.append(""); for(L2DropCategory cat:npcData.getDropData()) for(L2DropData drop : cat.getAllDrops()) { replyMSG.append("" + ""); } replyMSG.append("
npc_id itemId categoryitem[id]typedel
" + npcData.npcId + " " + drop.getItemId() + " " + cat.getCategoryType() + "" + ItemTable.getInstance().getTemplate(drop.getItemId()).getName() + "[" + drop.getItemId() + "]" + "" + (drop.isQuestDrop()?"Q":(cat.isSweep()?"S":"D")) + "" + "del
"); replyMSG.append("
"); replyMSG.append("
"); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } private void showEditDropData(L2PcInstance admin, int npcId, int itemId, int category) { java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("SELECT mobId, itemId, min, max, category, chance FROM droplist WHERE mobId=" + npcId + " AND itemId=" + itemId+ " AND category=" + category); ResultSet dropData = statement.executeQuery(); NpcHtmlMessage adminReply = new NpcHtmlMessage(5); TextBuilder replyMSG = new TextBuilder("the detail of dropdata: (" + npcId + " " + itemId + " " + category + ")"); replyMSG.append(""); if(dropData.next()){ replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
Appertain of NPC"+ NpcTable.getInstance().getTemplate(dropData.getInt("mobId")).name + "
ItemName"+ ItemTable.getInstance().getTemplate(dropData.getInt("itemId")).getName() + "(" + dropData.getInt("itemId") + ")
Category"+ ((category==-1)?"sweep":Integer.toString(category)) + "
MIN(" + dropData.getInt("min") + ")
MAX(" + dropData.getInt("max") + ")
CHANCE("+ dropData.getInt("chance") + ")
"); replyMSG.append("
"); replyMSG.append("
"); } dropData.close(); statement.close(); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } catch(Exception e){} finally { try { con.close(); } catch (Exception e) {} } } private void showAddDropData(L2PcInstance admin, L2NpcTemplate npcData) { NpcHtmlMessage adminReply = new NpcHtmlMessage(5); TextBuilder replyMSG = new TextBuilder("Add dropdata to " + npcData.name + "(" + npcData.npcId + ")"); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
Item-Id
MIN
MAX
CATEGORY(sweep=-1)
CHANCE(0-1000000)
"); replyMSG.append("
"); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } private void updateDropData(L2PcInstance admin, int npcId, int itemId, int min, int max, int category, int chance) { java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("UPDATE droplist SET min=?, max=?, chance=? WHERE mobId=? AND itemId=? AND category=?"); statement.setInt(1, min); statement.setInt(2, max); statement.setInt(3, chance); statement.setInt(4, npcId); statement.setInt(5, itemId); statement.setInt(6, category); statement.execute(); statement.close(); PreparedStatement statement2 = con.prepareStatement("SELECT mobId FROM droplist WHERE mobId=? AND itemId=? AND category=?"); statement2.setInt(1, npcId); statement2.setInt(2, itemId); statement2.setInt(3, category); ResultSet npcIdRs = statement2.executeQuery(); if(npcIdRs.next()) npcId = npcIdRs.getInt("mobId"); npcIdRs.close(); statement2.close(); if(npcId > 0) { reLoadNpcDropList(npcId); NpcHtmlMessage adminReply = new NpcHtmlMessage(5); TextBuilder replyMSG = new TextBuilder("Drop data modify complete!"); replyMSG.append(""); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } else { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("unknown error!"); admin.sendPacket(sm); } } catch(Exception e){ e.printStackTrace(); } finally { try { con.close(); } catch (Exception e) {} } //System.out.println("- updateDropData end"); } private void addDropData(L2PcInstance admin, int npcId, int itemId, int min, int max, int category, int chance) { java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("INSERT INTO droplist(mobId, itemId, min, max, category, chance) values(?,?,?,?,?,?)"); statement.setInt(1, npcId); statement.setInt(2, itemId); statement.setInt(3, min); statement.setInt(4, max); statement.setInt(5, category); statement.setInt(6, chance); statement.execute(); statement.close(); reLoadNpcDropList(npcId); NpcHtmlMessage adminReply = new NpcHtmlMessage(5); TextBuilder replyMSG = new TextBuilder("Add drop data complete!"); replyMSG.append(""); replyMSG.append("
"); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } catch(Exception e){} finally { try { con.close(); } catch (Exception e) {} } //System.out.println("- addDropData end"); } private void deleteDropData(L2PcInstance admin, int npcId, int itemId, int category) { java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); if(npcId > 0) { PreparedStatement statement2 = con.prepareStatement("DELETE FROM droplist WHERE mobId=? AND itemId=? AND category=?"); statement2.setInt(1, npcId); statement2.setInt(2, itemId); statement2.setInt(3, category); statement2.execute(); statement2.close(); reLoadNpcDropList(npcId); NpcHtmlMessage adminReply = new NpcHtmlMessage(5); TextBuilder replyMSG = new TextBuilder("Delete drop data(" + npcId+", "+ itemId+", "+ category + ")complete"); replyMSG.append(""); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } } catch(Exception e){} finally { try { con.close(); } catch (Exception e) {} } } private void reLoadNpcDropList(int npcId) { L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId); if (npcData == null) return; // reset the drop lists npcData.clearAllDropData(); // get the drops java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); L2DropData dropData = null; npcData.getDropData().clear(); PreparedStatement statement = con.prepareStatement("SELECT " + L2DatabaseFactory.getInstance().safetyString(new String[] {"mobId", "itemId", "min", "max", "category", "chance"}) + " FROM droplist WHERE mobId=?"); statement.setInt(1, npcId); ResultSet dropDataList = statement.executeQuery(); while(dropDataList.next()) { dropData = new L2DropData(); dropData.setItemId(dropDataList.getInt("itemId")); dropData.setMinDrop(dropDataList.getInt("min")); dropData.setMaxDrop(dropDataList.getInt("max")); dropData.setChance(dropDataList.getInt("chance")); int category = dropDataList.getInt("category"); npcData.addDropData(dropData, category); } dropDataList.close(); statement.close(); } catch(Exception e){} finally { try { con.close(); } catch (Exception e) {} } } // [L2J_JP ADD] private void showNpcSkillList(L2PcInstance admin, int npcId, int page) { L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId); if(npcData == null) { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("unknown npc template id" + npcId); admin.sendPacket(sm); return ; } Map skills = new FastMap(); if (npcData.getSkills() != null) { skills = npcData.getSkills(); } int _skillsize = Integer.valueOf(skills.size()); int MaxSkillsPerPage = 10; int MaxPages = _skillsize / MaxSkillsPerPage; if (_skillsize > MaxSkillsPerPage * MaxPages) MaxPages++; if (page>MaxPages) page = MaxPages; int SkillsStart = MaxSkillsPerPage * page; int SkillsEnd = _skillsize; if (SkillsEnd - SkillsStart > MaxSkillsPerPage) SkillsEnd = SkillsStart + MaxSkillsPerPage; NpcHtmlMessage adminReply = new NpcHtmlMessage(5); StringBuffer replyMSG = new StringBuffer(""); replyMSG.append(""+ npcData.name +" Skillist"); replyMSG.append(" (ID:"+npcData.npcId+" Skills "+Integer.valueOf(_skillsize)+")"); replyMSG.append(""); String pages = "
"; for (int x=0; x"; } else { pages += ""; } } pages += "
Page " + pagenr + "
"; replyMSG.append(pages); replyMSG.append(""); Set skillset = skills.keySet(); Iterator skillite = skillset.iterator(); Object skillobj = null; for (int i = 0; i < SkillsStart; i++) { if (skillite.hasNext()) { skillobj = skillite.next(); } } int cnt = SkillsStart; while (skillite.hasNext()) { cnt++; if (cnt > SkillsEnd) { break; } skillobj = skillite.next(); replyMSG.append("" + "" + ""); } replyMSG.append("
" + skills.get(skillobj).getName() + " [" + skills.get(skillobj).getId() + "]" + "" + skills.get(skillobj).getLevel() + "Á
"); replyMSG.append("

"); replyMSG.append("
"); replyMSG.append("
"); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } // [L2J_JP ADD] private void showNpcSkillEdit(L2PcInstance admin, int npcId, int skillId) { java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("SELECT npcid, skillid, level FROM npcskills WHERE npcid=" + npcId + " AND skillid=" + skillId); ResultSet skillData = statement.executeQuery(); NpcHtmlMessage adminReply = new NpcHtmlMessage(5); StringBuffer replyMSG = new StringBuffer("(NPC:" + npcId + " SKILL:" + skillId + ")"); replyMSG.append(""); if(skillData.next()){ L2Skill skill = SkillTable.getInstance().getInfo(skillData.getInt("skillid"),skillData.getInt("level")); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
NPC"+ NpcTable.getInstance().getTemplate(skillData.getInt("npcid")).name + "
SKILL"+ skill.getName() + "(" + skillData.getInt("skillid") + ")
Lv(" + skill.getLevel() + ")
"); replyMSG.append("
"); replyMSG.append("
"); } skillData.close(); statement.close(); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } catch(Exception e){} finally { try { con.close(); } catch (Exception e) {} } } // [L2J_JP ADD] private void updateNpcSkillData(L2PcInstance admin, int npcId, int skillId, int level) { java.sql.Connection con = null; try { // skill check L2Skill skillData = SkillTable.getInstance().getInfo(skillId,level); if (skillData == null) { NpcHtmlMessage adminReply = new NpcHtmlMessage(5); StringBuffer replyMSG = new StringBuffer("Update Npc Skill Data"); replyMSG.append(""); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); return; } con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("UPDATE npcskills SET level=? WHERE npcid=? AND skillid=?"); statement.setInt(1, level); statement.setInt(2, npcId); statement.setInt(3, skillId); statement.execute(); statement.close(); if(npcId > 0) { reLoadNpcSkillList(npcId); NpcHtmlMessage adminReply = new NpcHtmlMessage(5); StringBuffer replyMSG = new StringBuffer("Update Npc Skill Data"); replyMSG.append(""); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } else { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("unknown error!"); admin.sendPacket(sm); } } catch(Exception e){ e.printStackTrace(); } finally { try { con.close(); } catch (Exception e) {} } //System.out.println("- updateNpcSkillData end"); } // [L2J_JP ADD] private void showNpcSkillAdd(L2PcInstance admin, L2NpcTemplate npcData) { NpcHtmlMessage adminReply = new NpcHtmlMessage(5); StringBuffer replyMSG = new StringBuffer("Add Skill to " + npcData.name + "(ID:" + npcData.npcId + ")"); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
SkillId
Level
"); replyMSG.append("
"); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } // [L2J_JP ADD] private void addNpcSkillData(L2PcInstance admin, int npcId, int skillId, int level) { java.sql.Connection con = null; try { // skill check L2Skill skillData = SkillTable.getInstance().getInfo(skillId,level); if (skillData == null) { NpcHtmlMessage adminReply = new NpcHtmlMessage(5); StringBuffer replyMSG = new StringBuffer("Add Skill to Npc"); replyMSG.append(""); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); return; } con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("INSERT INTO npcskills(npcid, skillid, level) values(?,?,?)"); statement.setInt(1, npcId); statement.setInt(2, skillId); statement.setInt(3, level); statement.execute(); statement.close(); reLoadNpcSkillList(npcId); NpcHtmlMessage adminReply = new NpcHtmlMessage(5); StringBuffer replyMSG = new StringBuffer("Add Skill to Npc (" + npcId+", "+ skillId + ", "+ level + ")"); replyMSG.append(""); replyMSG.append("
"); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } catch(Exception e){} finally { try { con.close(); } catch (Exception e) {} } //System.out.println("- addNpcSkillData end"); } // [L2J_JP ADD] private void deleteNpcSkillData(L2PcInstance admin, int npcId, int skillId) { java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); if(npcId > 0) { PreparedStatement statement2 = con.prepareStatement("DELETE FROM npcskills WHERE npcid=? AND skillid=?"); statement2.setInt(1, npcId); statement2.setInt(2, skillId); statement2.execute(); statement2.close(); reLoadNpcSkillList(npcId); NpcHtmlMessage adminReply = new NpcHtmlMessage(5); StringBuffer replyMSG = new StringBuffer("Delete Skill (" + npcId+", "+ skillId + ")"); replyMSG.append(""); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); admin.sendPacket(adminReply); } } catch(Exception e){} finally { try { con.close(); } catch (Exception e) {} } } // [L2J_JP ADD] private void reLoadNpcSkillList(int npcId) { java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId); L2Skill skillData = null; if (npcData.getSkills() != null) { npcData.getSkills().clear(); } // with out race String _sql = "SELECT npcid, skillid, level FROM npcskills WHERE npcid=? AND (skillid NOT BETWEEN 4290 AND 4302)"; PreparedStatement statement = con.prepareStatement(_sql); statement.setInt(1, npcId); ResultSet skillDataList = statement.executeQuery(); int i = 1; while(skillDataList.next()) { int idval = skillDataList.getInt("skillid"); int levelval = skillDataList.getInt("level"); skillData = SkillTable.getInstance().getInfo(idval,levelval); if (skillData != null) { npcData.addSkill(skillData); } i++; } skillDataList.close(); statement.close(); } catch(Exception e){} finally { try { con.close(); } catch (Exception e) {} } } }