AdminEditNpc.java 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.handler.admincommandhandlers;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.sql.SQLException;
  19. import java.util.List;
  20. import java.util.StringTokenizer;
  21. import java.util.logging.Logger;
  22. import javolution.text.TextBuilder;
  23. import javolution.util.FastList;
  24. import net.sf.l2j.L2DatabaseFactory;
  25. import net.sf.l2j.gameserver.TradeController;
  26. import net.sf.l2j.gameserver.cache.HtmCache;
  27. import net.sf.l2j.gameserver.datatables.ItemTable;
  28. import net.sf.l2j.gameserver.datatables.NpcTable;
  29. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  30. import net.sf.l2j.gameserver.model.L2DropCategory;
  31. import net.sf.l2j.gameserver.model.L2DropData;
  32. import net.sf.l2j.gameserver.model.L2TradeList;
  33. import net.sf.l2j.gameserver.model.L2TradeList.L2TradeItem;
  34. import net.sf.l2j.gameserver.model.actor.instance.L2MerchantInstance;
  35. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  36. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  37. import net.sf.l2j.gameserver.templates.L2Item;
  38. import net.sf.l2j.gameserver.templates.L2NpcTemplate;
  39. import net.sf.l2j.gameserver.templates.StatsSet;
  40. /**
  41. * @author terry
  42. *
  43. * Window - Preferences - Java - Code Style - Code Templates
  44. */
  45. public class AdminEditNpc implements IAdminCommandHandler {
  46. private static Logger _log = Logger.getLogger(AdminEditChar.class.getName());
  47. private final static int PAGE_LIMIT = 7;
  48. private static final String[] ADMIN_COMMANDS = {
  49. "admin_edit_npc",
  50. "admin_save_npc",
  51. "admin_show_droplist",
  52. "admin_edit_drop",
  53. "admin_add_drop",
  54. "admin_del_drop",
  55. "admin_showShop",
  56. "admin_showShopList",
  57. "admin_addShopItem",
  58. "admin_delShopItem",
  59. "admin_editShopItem",
  60. "admin_close_window"
  61. };
  62. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  63. {//TODO: Tokenize and protect arguments parsing. Externalize HTML.
  64. if (command.startsWith("admin_showShop "))
  65. {
  66. String[] args = command.split(" ");
  67. if (args.length > 1)
  68. showShop(activeChar, Integer.parseInt(command.split(" ")[1]));
  69. }
  70. else if(command.startsWith("admin_showShopList "))
  71. {
  72. String[] args = command.split(" ");
  73. if (args.length > 2)
  74. showShopList(activeChar, Integer.parseInt(command.split(" ")[1]), Integer.parseInt(command.split(" ")[2]));
  75. }
  76. else if(command.startsWith("admin_edit_npc "))
  77. {
  78. try
  79. {
  80. String[] commandSplit = command.split(" ");
  81. int npcId = Integer.valueOf(commandSplit[1]);
  82. L2NpcTemplate npc = NpcTable.getInstance().getTemplate(npcId);
  83. Show_Npc_Property(activeChar, npc);
  84. }
  85. catch (Exception e)
  86. {
  87. activeChar.sendMessage("Wrong usage: //edit_npc <npcId>");
  88. }
  89. }
  90. else if(command.startsWith("admin_show_droplist "))
  91. {
  92. int npcId = 0;
  93. try
  94. {
  95. npcId = Integer.parseInt(command.substring(20).trim());
  96. }
  97. catch(Exception e){}
  98. if(npcId > 0)
  99. showNpcDropList(activeChar, npcId);
  100. else
  101. activeChar.sendMessage("Usage: //show_droplist <npc_id>");
  102. }
  103. else if(command.startsWith("admin_addShopItem "))
  104. {
  105. String[] args = command.split(" ");
  106. if (args.length > 1)
  107. addShopItem(activeChar, args);
  108. }
  109. else if(command.startsWith("admin_delShopItem "))
  110. {
  111. String[] args = command.split(" ");
  112. if (args.length > 2)
  113. delShopItem(activeChar, args);
  114. }
  115. else if(command.startsWith("admin_editShopItem "))
  116. {
  117. String[] args = command.split(" ");
  118. if (args.length > 2)
  119. editShopItem(activeChar, args);
  120. }
  121. else if(command.startsWith("admin_save_npc "))
  122. {
  123. try
  124. {
  125. save_npc_property(activeChar, command);
  126. }
  127. catch (StringIndexOutOfBoundsException e)
  128. {}
  129. }
  130. else if(command.startsWith("admin_edit_drop "))
  131. {
  132. int npcId = -1, itemId = 0, category = -1000;
  133. try
  134. {
  135. StringTokenizer st = new StringTokenizer(command.substring(16).trim());
  136. if (st.countTokens() == 3)
  137. {
  138. try
  139. {
  140. npcId = Integer.parseInt(st.nextToken());
  141. itemId = Integer.parseInt(st.nextToken());
  142. category = Integer.parseInt(st.nextToken());
  143. showEditDropData(activeChar, npcId, itemId, category);
  144. }
  145. catch(Exception e)
  146. {}
  147. }
  148. else if (st.countTokens() == 6)
  149. {
  150. try
  151. {
  152. npcId = Integer.parseInt(st.nextToken());
  153. itemId = Integer.parseInt(st.nextToken());
  154. category = Integer.parseInt(st.nextToken());
  155. int min = Integer.parseInt(st.nextToken());
  156. int max = Integer.parseInt(st.nextToken());
  157. int chance = Integer.parseInt(st.nextToken());
  158. updateDropData(activeChar, npcId, itemId, min, max, category, chance);
  159. }
  160. catch(Exception e)
  161. {
  162. _log.fine("admin_edit_drop parements error: " + command);
  163. }
  164. }
  165. else
  166. activeChar.sendMessage("Usage: //edit_drop <npc_id> <item_id> <category> [<min> <max> <chance>]");
  167. }
  168. catch (StringIndexOutOfBoundsException e)
  169. {
  170. activeChar.sendMessage("Usage: //edit_drop <npc_id> <item_id> <category> [<min> <max> <chance>]");
  171. }
  172. }
  173. else if (command.startsWith("admin_add_drop "))
  174. {
  175. int npcId = -1;
  176. try
  177. {
  178. StringTokenizer st = new StringTokenizer(command.substring(15).trim());
  179. if(st.countTokens() == 1)
  180. {
  181. try
  182. {
  183. String[] input = command.substring(15).split(" ");
  184. if (input.length < 1)
  185. return true;
  186. npcId = Integer.parseInt(input[0]);
  187. }
  188. catch(Exception e){}
  189. if(npcId > 0)
  190. {
  191. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  192. showAddDropData(activeChar, npcData);
  193. }
  194. }
  195. else if(st.countTokens() == 6)
  196. {
  197. try
  198. {
  199. npcId = Integer.parseInt(st.nextToken());
  200. int itemId = Integer.parseInt(st.nextToken());
  201. int category = Integer.parseInt(st.nextToken());
  202. int min = Integer.parseInt(st.nextToken());
  203. int max = Integer.parseInt(st.nextToken());
  204. int chance = Integer.parseInt(st.nextToken());
  205. addDropData(activeChar, npcId, itemId, min, max, category, chance);
  206. }
  207. catch(Exception e)
  208. {
  209. _log.fine("admin_add_drop parements error: " + command);
  210. }
  211. }
  212. else
  213. activeChar.sendMessage("Usage: //add_drop <npc_id> [<item_id> <category> <min> <max> <chance>]");
  214. }
  215. catch (StringIndexOutOfBoundsException e)
  216. {
  217. activeChar.sendMessage("Usage: //add_drop <npc_id> [<item_id> <category> <min> <max> <chance>]");
  218. }
  219. }
  220. else if(command.startsWith("admin_del_drop "))
  221. {
  222. int npcId = -1, itemId = -1, category = -1000;
  223. try
  224. {
  225. String[] input = command.substring(15).split(" ");
  226. if (input.length >= 3)
  227. {
  228. npcId = Integer.parseInt(input[0]);
  229. itemId = Integer.parseInt(input[1]);
  230. category = Integer.parseInt(input[2]);
  231. }
  232. }
  233. catch(Exception e){}
  234. if(npcId > 0)
  235. deleteDropData(activeChar, npcId, itemId, category);
  236. else
  237. activeChar.sendMessage("Usage: //del_drop <npc_id> <item_id> <category>");
  238. }
  239. return true;
  240. }
  241. private void editShopItem(L2PcInstance activeChar, String[] args)
  242. {
  243. int tradeListID = Integer.parseInt(args[1]);
  244. int itemID = Integer.parseInt(args[2]);
  245. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  246. L2Item item = ItemTable.getInstance().getTemplate(itemID);
  247. if (tradeList.getPriceForItemId(itemID) < 0)
  248. {
  249. return;
  250. }
  251. if (args.length > 3)
  252. {
  253. int price = Integer.parseInt(args[3]);
  254. int order = findOrderTradeList(itemID, tradeList.getPriceForItemId(itemID), tradeListID);
  255. tradeList.replaceItem(itemID, Integer.parseInt(args[3]));
  256. updateTradeList(itemID, price, tradeListID, order);
  257. activeChar.sendMessage("Updated price for "+item.getName()+" in Trade List "+tradeListID);
  258. showShopList(activeChar, tradeListID, 1);
  259. return;
  260. }
  261. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  262. TextBuilder replyMSG = new TextBuilder();
  263. replyMSG.append("<html><title>Merchant Shop Item Edit</title>");
  264. replyMSG.append("<body>");
  265. replyMSG.append("<br>Edit an entry in merchantList.");
  266. replyMSG.append("<br>Editing Item: "+item.getName());
  267. replyMSG.append("<table>");
  268. replyMSG.append("<tr><td width=100>Property</td><td width=100>Edit Field</td><td width=100>Old Value</td></tr>");
  269. replyMSG.append("<tr><td><br></td><td></td></tr>");
  270. replyMSG.append("<tr><td>Price</td><td><edit var=\"price\" width=80></td><td>"+tradeList.getPriceForItemId(itemID)+"</td></tr>");
  271. replyMSG.append("</table>");
  272. replyMSG.append("<center><br><br><br>");
  273. replyMSG.append("<button value=\"Save\" action=\"bypass -h admin_editShopItem " + tradeListID + " " + itemID + " $price\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  274. replyMSG.append("<br><button value=\"Back\" action=\"bypass -h admin_showShopList " + tradeListID +" 1\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  275. replyMSG.append("</center>");
  276. replyMSG.append("</body></html>");
  277. adminReply.setHtml(replyMSG.toString());
  278. activeChar.sendPacket(adminReply);
  279. }
  280. private void delShopItem(L2PcInstance activeChar, String[] args)
  281. {
  282. int tradeListID = Integer.parseInt(args[1]);
  283. int itemID = Integer.parseInt(args[2]);
  284. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  285. if (tradeList.getPriceForItemId(itemID) < 0)
  286. return;
  287. if (args.length > 3)
  288. {
  289. int order = findOrderTradeList(itemID, tradeList.getPriceForItemId(itemID), tradeListID);
  290. tradeList.removeItem(itemID);
  291. deleteTradeList(tradeListID, order);
  292. activeChar.sendMessage("Deleted "+ItemTable.getInstance().getTemplate(itemID).getName()+" from Trade List "+tradeListID);
  293. showShopList(activeChar, tradeListID, 1);
  294. return;
  295. }
  296. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  297. TextBuilder replyMSG = new TextBuilder();
  298. replyMSG.append("<html><title>Merchant Shop Item Delete</title>");
  299. replyMSG.append("<body>");
  300. replyMSG.append("<br>Delete entry in merchantList.");
  301. replyMSG.append("<br>Item to Delete: "+ItemTable.getInstance().getTemplate(itemID).getName());
  302. replyMSG.append("<table>");
  303. replyMSG.append("<tr><td width=100>Property</td><td width=100>Value</td></tr>");
  304. replyMSG.append("<tr><td><br></td><td></td></tr>");
  305. replyMSG.append("<tr><td>Price</td><td>"+tradeList.getPriceForItemId(itemID)+"</td></tr>");
  306. replyMSG.append("</table>");
  307. replyMSG.append("<center><br><br><br>");
  308. replyMSG.append("<button value=\"Confirm\" action=\"bypass -h admin_delShopItem " + tradeListID + " " + itemID + " 1\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  309. replyMSG.append("<br><button value=\"Back\" action=\"bypass -h admin_showShopList " + tradeListID +" 1\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  310. replyMSG.append("</center>");
  311. replyMSG.append("</body></html>");
  312. adminReply.setHtml(replyMSG.toString());
  313. activeChar.sendPacket(adminReply);
  314. }
  315. private void addShopItem(L2PcInstance activeChar, String[] args)
  316. {
  317. int tradeListID = Integer.parseInt(args[1]);
  318. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  319. if (tradeList == null)
  320. {
  321. activeChar.sendMessage("TradeList not found!");
  322. return;
  323. }
  324. if (args.length > 3)
  325. {
  326. int order = tradeList.getItems().size() + 1; // last item order + 1
  327. int itemID = Integer.parseInt(args[2]);
  328. int price = Integer.parseInt(args[3]);
  329. L2TradeItem newItem = new L2TradeItem(itemID);
  330. newItem.setPrice(price);
  331. newItem.setMaxCount(-1);
  332. tradeList.addItem(newItem);
  333. storeTradeList(itemID, price, tradeListID, order);
  334. activeChar.sendMessage("Added "+ItemTable.getInstance().getTemplate(itemID).getName()+" to Trade List "+tradeList.getListId());
  335. showShopList(activeChar, tradeListID, 1);
  336. return;
  337. }
  338. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  339. TextBuilder replyMSG = new TextBuilder();
  340. replyMSG.append("<html><title>Merchant Shop Item Add</title>");
  341. replyMSG.append("<body>");
  342. replyMSG.append("<br>Add a new entry in merchantList.");
  343. replyMSG.append("<table>");
  344. replyMSG.append("<tr><td width=100>Property</td><td>Edit Field</td></tr>");
  345. replyMSG.append("<tr><td><br></td><td></td></tr>");
  346. replyMSG.append("<tr><td>ItemID</td><td><edit var=\"itemID\" width=80></td></tr>");
  347. replyMSG.append("<tr><td>Price</td><td><edit var=\"price\" width=80></td></tr>");
  348. replyMSG.append("</table>");
  349. replyMSG.append("<center><br><br><br>");
  350. replyMSG.append("<button value=\"Save\" action=\"bypass -h admin_addShopItem " + tradeListID + " $itemID $price\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  351. replyMSG.append("<br><button value=\"Back\" action=\"bypass -h admin_showShopList " + tradeListID +" 1\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  352. replyMSG.append("</center>");
  353. replyMSG.append("</body></html>");
  354. adminReply.setHtml(replyMSG.toString());
  355. activeChar.sendPacket(adminReply);
  356. }
  357. private void showShopList(L2PcInstance activeChar, int tradeListID, int page)
  358. {
  359. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  360. if (page > tradeList.getItems().size() / PAGE_LIMIT + 1 || page < 1)
  361. return;
  362. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  363. TextBuilder html = itemListHtml(tradeList, page);
  364. adminReply.setHtml(html.toString());
  365. activeChar.sendPacket(adminReply);
  366. }
  367. private TextBuilder itemListHtml(L2TradeList tradeList, int page)
  368. {
  369. TextBuilder replyMSG = new TextBuilder();
  370. replyMSG.append("<html><title>Merchant Shop List Page: "+page+"</title>");
  371. replyMSG.append("<body>");
  372. replyMSG.append("<br>Edit, add or delete entries in a merchantList.");
  373. replyMSG.append("<table>");
  374. replyMSG.append("<tr><td width=150>Item Name</td><td width=60>Price</td><td width=40>Delete</td></tr>");
  375. int start = ((page-1) * PAGE_LIMIT);
  376. int end = Math.min(((page-1) * PAGE_LIMIT) + (PAGE_LIMIT-1), tradeList.getItems().size() - 1);
  377. for (L2TradeItem item : tradeList.getItems(start, end+1))
  378. {
  379. replyMSG.append("<tr><td><a action=\"bypass -h admin_editShopItem "+tradeList.getListId()+" "+item.getItemId()+"\">"+ItemTable.getInstance().getTemplate(item.getItemId()).getName()+"</a></td>");
  380. replyMSG.append("<td>"+item.getPrice()+"</td>");
  381. replyMSG.append("<td><button value=\"Del\" action=\"bypass -h admin_delShopItem "+tradeList.getListId()+" "+item.getItemId()+"\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  382. replyMSG.append("</tr>");
  383. }//*/
  384. replyMSG.append("<tr>");
  385. int min = 1;
  386. int max = tradeList.getItems().size() / PAGE_LIMIT + 1;
  387. if (page > 1)
  388. {
  389. replyMSG.append("<td><button value=\"Page"+(page - 1)+"\" action=\"bypass -h admin_showShopList "+tradeList.getListId()+" "+(page - 1)+"\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  390. }
  391. if (page < max)
  392. {
  393. if (page <= min)
  394. replyMSG.append("<td></td>");
  395. replyMSG.append("<td><button value=\"Page"+(page + 1)+"\" action=\"bypass -h admin_showShopList "+tradeList.getListId()+" "+(page + 1)+"\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  396. }
  397. replyMSG.append("</tr><tr><td>.</td></tr>");
  398. replyMSG.append("</table>");
  399. replyMSG.append("<center>");
  400. replyMSG.append("<button value=\"Add\" action=\"bypass -h admin_addShopItem "+tradeList.getListId()+"\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  401. replyMSG.append("<button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  402. replyMSG.append("</center></body></html>");
  403. return replyMSG;
  404. }
  405. private void showShop(L2PcInstance activeChar, int merchantID)
  406. {
  407. List<L2TradeList> tradeLists = getTradeLists(merchantID);
  408. if(tradeLists == null)
  409. {
  410. activeChar.sendMessage("Unknown npc template Id: " + merchantID);
  411. return ;
  412. }
  413. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  414. TextBuilder replyMSG = new TextBuilder("<html><title>Merchant Shop Lists</title>");
  415. replyMSG.append("<body>");
  416. if (activeChar.getTarget() instanceof L2MerchantInstance)
  417. {
  418. String mpcName = ((L2MerchantInstance) activeChar.getTarget()).getMpc().getName();
  419. replyMSG.append("<br>NPC: "+activeChar.getTarget().getName());
  420. replyMSG.append("<br>Price Config: "+mpcName);
  421. }
  422. replyMSG.append("<br>Select a list to view");
  423. replyMSG.append("<table>");
  424. replyMSG.append("<tr><td>Mecrchant List ID</td></tr>");
  425. for (L2TradeList tradeList : tradeLists)
  426. {
  427. if (tradeList != null)
  428. replyMSG.append("<tr><td><a action=\"bypass -h admin_showShopList "+tradeList.getListId()+" 1\">Trade List "+tradeList.getListId()+"</a></td></tr>");
  429. }
  430. replyMSG.append("</table>");
  431. replyMSG.append("<center>");
  432. replyMSG.append("<button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  433. replyMSG.append("</center></body></html>");
  434. adminReply.setHtml(replyMSG.toString());
  435. activeChar.sendPacket(adminReply);
  436. }
  437. private void storeTradeList(int itemID, int price, int tradeListID, int order)
  438. {
  439. java.sql.Connection con = null;
  440. try
  441. {
  442. con = L2DatabaseFactory.getInstance().getConnection();
  443. PreparedStatement stmt = con.prepareStatement("INSERT INTO merchant_buylists (`item_id`,`price`,`shop_id`,`order`) values ("+itemID+","+price+","+tradeListID+","+order+")");
  444. stmt.execute();
  445. stmt.close();
  446. }
  447. catch (SQLException esql)
  448. {
  449. esql.printStackTrace();
  450. }
  451. finally
  452. {
  453. try
  454. {
  455. con.close();
  456. }
  457. catch (SQLException e)
  458. {
  459. e.printStackTrace();
  460. }
  461. }
  462. }
  463. private void updateTradeList(int itemID, int price, int tradeListID, int order)
  464. {
  465. java.sql.Connection con = null;
  466. try
  467. {
  468. con = L2DatabaseFactory.getInstance().getConnection();
  469. PreparedStatement stmt = con.prepareStatement("UPDATE merchant_buylists SET `price`='"+price+"' WHERE `shop_id`='"+tradeListID+"' AND `order`='"+order+"'");
  470. stmt.execute();
  471. stmt.close();
  472. }catch (SQLException esql)
  473. {
  474. esql.printStackTrace();
  475. }
  476. finally
  477. {
  478. try
  479. {
  480. con.close();
  481. }
  482. catch (SQLException e)
  483. {
  484. e.printStackTrace();
  485. }
  486. }
  487. }
  488. private void deleteTradeList(int tradeListID, int order)
  489. {
  490. java.sql.Connection con = null;
  491. try
  492. {
  493. con = L2DatabaseFactory.getInstance().getConnection();
  494. PreparedStatement stmt = con.prepareStatement("DELETE FROM merchant_buylists WHERE `shop_id`='"+tradeListID+"' AND `order`='"+order+"'");
  495. stmt.execute();
  496. stmt.close();
  497. }
  498. catch (SQLException esql)
  499. {
  500. esql.printStackTrace();
  501. }
  502. finally
  503. {
  504. try
  505. {
  506. con.close();
  507. }
  508. catch (SQLException e)
  509. {
  510. e.printStackTrace();
  511. }
  512. }
  513. }
  514. private int findOrderTradeList(int itemID, int price, int tradeListID)
  515. {
  516. java.sql.Connection con = null;
  517. int order = 0;
  518. try
  519. {
  520. con = L2DatabaseFactory.getInstance().getConnection();
  521. PreparedStatement stmt = con.prepareStatement("SELECT * FROM merchant_buylists WHERE `shop_id`='"+tradeListID+"' AND `item_id` ='"+itemID+"' AND `price` = '"+price+"'");
  522. ResultSet rs = stmt.executeQuery();
  523. rs.first();
  524. order = rs.getInt("order");
  525. stmt.close();
  526. rs.close();
  527. }
  528. catch (SQLException esql)
  529. {
  530. esql.printStackTrace();
  531. }
  532. finally
  533. {
  534. try
  535. {
  536. con.close();
  537. }
  538. catch (SQLException e)
  539. {
  540. e.printStackTrace();
  541. }
  542. }
  543. return order;
  544. }
  545. private List<L2TradeList> getTradeLists(int merchantID)
  546. {
  547. String target = "npc_%objectId%_Buy";
  548. String content = HtmCache.getInstance().getHtm("data/html/merchant/"+merchantID+".htm");
  549. if (content == null)
  550. {
  551. content = HtmCache.getInstance().getHtm("data/html/merchant/30001.htm");
  552. if (content == null)
  553. return null;
  554. }
  555. List<L2TradeList> tradeLists = new FastList<L2TradeList>();
  556. String[] lines = content.split("\n");
  557. int pos = 0;
  558. for (String line : lines)
  559. {
  560. pos = line.indexOf(target);
  561. if (pos >= 0)
  562. {
  563. int tradeListID = Integer.decode((line.substring(pos+target.length()+1)).split("\"")[0]);
  564. tradeLists.add(TradeController.getInstance().getBuyList(tradeListID));
  565. }
  566. }
  567. return tradeLists;
  568. }
  569. public String[] getAdminCommandList() {
  570. return ADMIN_COMMANDS;
  571. }
  572. private void Show_Npc_Property(L2PcInstance activeChar, L2NpcTemplate npc)
  573. {
  574. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  575. String content = HtmCache.getInstance().getHtm("data/html/admin/editnpc.htm");
  576. if (content != null)
  577. {
  578. adminReply.setHtml(content);
  579. adminReply.replace("%npcId%", String.valueOf(npc.npcId));
  580. adminReply.replace("%templateId%", String.valueOf(npc.idTemplate));
  581. adminReply.replace("%name%", npc.name);
  582. adminReply.replace("%serverSideName%", npc.serverSideName == true ? "1" : "0");
  583. adminReply.replace("%title%", npc.title);
  584. adminReply.replace("%serverSideTitle%", npc.serverSideTitle == true ? "1" : "0");
  585. adminReply.replace("%collisionRadius%", String.valueOf(npc.collisionRadius));
  586. adminReply.replace("%collisionHeight%", String.valueOf(npc.collisionHeight));
  587. adminReply.replace("%level%", String.valueOf(npc.level));
  588. adminReply.replace("%sex%", String.valueOf(npc.sex));
  589. adminReply.replace("%type%", String.valueOf(npc.type));
  590. adminReply.replace("%attackRange%", String.valueOf(npc.baseAtkRange));
  591. adminReply.replace("%hp%", String.valueOf(npc.baseHpMax));
  592. adminReply.replace("%mp%", String.valueOf(npc.baseMpMax));
  593. adminReply.replace("%hpRegen%", String.valueOf(npc.baseHpReg));
  594. adminReply.replace("%mpRegen%", String.valueOf(npc.baseMpReg));
  595. adminReply.replace("%str%", String.valueOf(npc.baseSTR));
  596. adminReply.replace("%con%", String.valueOf(npc.baseCON));
  597. adminReply.replace("%dex%", String.valueOf(npc.baseDEX));
  598. adminReply.replace("%int%", String.valueOf(npc.baseINT));
  599. adminReply.replace("%wit%", String.valueOf(npc.baseWIT));
  600. adminReply.replace("%men%", String.valueOf(npc.baseMEN));
  601. adminReply.replace("%exp%", String.valueOf(npc.rewardExp));
  602. adminReply.replace("%sp%", String.valueOf(npc.rewardSp));
  603. adminReply.replace("%pAtk%", String.valueOf(npc.basePAtk));
  604. adminReply.replace("%pDef%", String.valueOf(npc.basePDef));
  605. adminReply.replace("%mAtk%", String.valueOf(npc.baseMAtk));
  606. adminReply.replace("%mDef%", String.valueOf(npc.baseMDef));
  607. adminReply.replace("%pAtkSpd%", String.valueOf(npc.basePAtkSpd));
  608. adminReply.replace("%aggro%", String.valueOf(npc.aggroRange));
  609. adminReply.replace("%mAtkSpd%", String.valueOf(npc.baseMAtkSpd));
  610. adminReply.replace("%rHand%", String.valueOf(npc.rhand));
  611. adminReply.replace("%lHand%", String.valueOf(npc.lhand));
  612. adminReply.replace("%armor%", String.valueOf(npc.armor));
  613. adminReply.replace("%walkSpd%", String.valueOf(npc.baseWalkSpd));
  614. adminReply.replace("%runSpd%", String.valueOf(npc.baseRunSpd));
  615. adminReply.replace("%factionId%", npc.factionId == null ? "" : npc.factionId);
  616. adminReply.replace("%factionRange%", String.valueOf(npc.factionRange));
  617. adminReply.replace("%isUndead%", npc.isUndead ? "1" : "0");
  618. adminReply.replace("%absorbLevel%", String.valueOf(npc.absorbLevel));
  619. }
  620. else
  621. adminReply.setHtml("<html><head><body>File not found: data/html/admin/editnpc.htm</body></html>");
  622. activeChar.sendPacket(adminReply);
  623. }
  624. private void save_npc_property(L2PcInstance activeChar, String command)
  625. {
  626. String[] commandSplit = command.split(" ");
  627. if (commandSplit.length < 4)
  628. return;
  629. StatsSet newNpcData = new StatsSet();
  630. try
  631. {
  632. newNpcData.set("npcId", commandSplit[1]);
  633. String statToSet = commandSplit[2];
  634. String value = commandSplit[3];
  635. if (commandSplit.length > 4)
  636. {
  637. for (int i=0;i<commandSplit.length-3;i++)
  638. value += " " + commandSplit[i+4];
  639. }
  640. if (statToSet.equals("templateId"))
  641. newNpcData.set("idTemplate", Integer.valueOf(value));
  642. else if (statToSet.equals("name"))
  643. newNpcData.set("name", value);
  644. else if (statToSet.equals("serverSideName"))
  645. newNpcData.set("serverSideName", Integer.valueOf(value));
  646. else if (statToSet.equals("title"))
  647. newNpcData.set("title", value);
  648. else if (statToSet.equals("serverSideTitle"))
  649. newNpcData.set("serverSideTitle", Integer.valueOf(value) == 1 ? 1 : 0);
  650. else if (statToSet.equals("collisionRadius"))
  651. newNpcData.set("collision_radius", Integer.valueOf(value));
  652. else if (statToSet.equals("collisionHeight"))
  653. newNpcData.set("collision_height", Integer.valueOf(value));
  654. else if (statToSet.equals("level"))
  655. newNpcData.set("level", Integer.valueOf(value));
  656. else if (statToSet.equals("sex"))
  657. {
  658. int intValue = Integer.valueOf(value);
  659. newNpcData.set("sex", intValue == 0 ? "male" : intValue == 1 ? "female" : "etc");
  660. }
  661. else if (statToSet.equals("type"))
  662. {
  663. Class.forName("net.sf.l2j.gameserver.model.actor.instance." + value + "Instance");
  664. newNpcData.set("type", value);
  665. }
  666. else if (statToSet.equals("attackRange"))
  667. newNpcData.set("attackrange", Integer.valueOf(value));
  668. else if (statToSet.equals("hp"))
  669. newNpcData.set("hp", Integer.valueOf(value));
  670. else if (statToSet.equals("mp"))
  671. newNpcData.set("mp", Integer.valueOf(value));
  672. else if (statToSet.equals("hpRegen"))
  673. newNpcData.set("hpreg", Integer.valueOf(value));
  674. else if (statToSet.equals("mpRegen"))
  675. newNpcData.set("mpreg", Integer.valueOf(value));
  676. else if (statToSet.equals("str"))
  677. newNpcData.set("str", Integer.valueOf(value));
  678. else if (statToSet.equals("con"))
  679. newNpcData.set("con", Integer.valueOf(value));
  680. else if (statToSet.equals("dex"))
  681. newNpcData.set("dex", Integer.valueOf(value));
  682. else if (statToSet.equals("int"))
  683. newNpcData.set("int", Integer.valueOf(value));
  684. else if (statToSet.equals("wit"))
  685. newNpcData.set("wit", Integer.valueOf(value));
  686. else if (statToSet.equals("men"))
  687. newNpcData.set("men", Integer.valueOf(value));
  688. else if (statToSet.equals("exp"))
  689. newNpcData.set("exp", Integer.valueOf(value));
  690. else if (statToSet.equals("sp"))
  691. newNpcData.set("sp", Integer.valueOf(value));
  692. else if (statToSet.equals("pAtk"))
  693. newNpcData.set("patk", Integer.valueOf(value));
  694. else if (statToSet.equals("pDef"))
  695. newNpcData.set("pdef", Integer.valueOf(value));
  696. else if (statToSet.equals("mAtk"))
  697. newNpcData.set("matk", Integer.valueOf(value));
  698. else if (statToSet.equals("mDef"))
  699. newNpcData.set("mdef", Integer.valueOf(value));
  700. else if (statToSet.equals("pAtkSpd"))
  701. newNpcData.set("atkspd", Integer.valueOf(value));
  702. else if (statToSet.equals("aggro"))
  703. newNpcData.set("aggro", Integer.valueOf(value));
  704. else if (statToSet.equals("mAtkSpd"))
  705. newNpcData.set("matkspd", Integer.valueOf(value));
  706. else if (statToSet.equals("rHand"))
  707. newNpcData.set("rhand", Integer.valueOf(value));
  708. else if (statToSet.equals("lHand"))
  709. newNpcData.set("lhand", Integer.valueOf(value));
  710. else if (statToSet.equals("armor"))
  711. newNpcData.set("armor", Integer.valueOf(value));
  712. else if (statToSet.equals("runSpd"))
  713. newNpcData.set("runspd", Integer.valueOf(value));
  714. else if (statToSet.equals("factionId"))
  715. newNpcData.set("faction_id", value);
  716. else if (statToSet.equals("factionRange"))
  717. newNpcData.set("faction_range", Integer.valueOf(value));
  718. else if (statToSet.equals("isUndead"))
  719. newNpcData.set("isUndead", Integer.valueOf(value) == 1 ? 1 : 0);
  720. else if (statToSet.equals("absorbLevel"))
  721. {
  722. int intVal = Integer.valueOf(value);
  723. newNpcData.set("absorb_level", intVal < 0 ? 0 : intVal > 12 ? 0 : intVal);
  724. }
  725. }
  726. catch (Exception e)
  727. {
  728. _log.warning("Error saving new npc value: " + e);
  729. }
  730. NpcTable.getInstance().saveNpc(newNpcData);
  731. int npcId = newNpcData.getInteger("npcId");
  732. NpcTable.getInstance().reloadNpc(npcId);
  733. Show_Npc_Property(activeChar, NpcTable.getInstance().getTemplate(npcId));
  734. }
  735. private void showNpcDropList(L2PcInstance activeChar, int npcId)
  736. {
  737. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  738. if(npcData == null)
  739. {
  740. activeChar.sendMessage("unknown npc template id" + npcId);
  741. return ;
  742. }
  743. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  744. TextBuilder replyMSG = new TextBuilder("<html><title>NPC: "+ npcData.name + "("+npcData.npcId+") 's drop manage</title>");
  745. replyMSG.append("<body>");
  746. replyMSG.append("<br>Notes: click[drop_id]to show the detail of drop data,click[del] to delete the drop data!");
  747. replyMSG.append("<table>");
  748. replyMSG.append("<tr><td>npc_id itemId category</td><td>item[id]</td><td>type</td><td>del</td></tr>");
  749. if (npcData.getDropData()!=null)
  750. for(L2DropCategory cat:npcData.getDropData())
  751. for(L2DropData drop : cat.getAllDrops())
  752. {
  753. replyMSG.append("<tr><td><a action=\"bypass -h admin_edit_drop " + npcData.npcId + " " + drop.getItemId()+ " " + cat.getCategoryType() + "\">"
  754. + npcData.npcId + " " + drop.getItemId() + " " + cat.getCategoryType() + "</a></td>" +
  755. "<td>" + ItemTable.getInstance().getTemplate(drop.getItemId()).getName() + "[" + drop.getItemId() + "]" + "</td><td>" + (drop.isQuestDrop()?"Q":(cat.isSweep()?"S":"D")) + "</td><td>" +
  756. "<a action=\"bypass -h admin_del_drop " + npcData.npcId + " " + drop.getItemId() +" "+ cat.getCategoryType() +"\">del</a></td></tr>");
  757. }
  758. replyMSG.append("</table>");
  759. replyMSG.append("<center>");
  760. replyMSG.append("<button value=\"Add DropData\" action=\"bypass -h admin_add_drop "+ npcId + "\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  761. replyMSG.append("<button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  762. replyMSG.append("</center></body></html>");
  763. adminReply.setHtml(replyMSG.toString());
  764. activeChar.sendPacket(adminReply);
  765. }
  766. private void showEditDropData(L2PcInstance activeChar, int npcId, int itemId, int category)
  767. {
  768. java.sql.Connection con = null;
  769. try
  770. {
  771. con = L2DatabaseFactory.getInstance().getConnection();
  772. PreparedStatement statement = con.prepareStatement("SELECT mobId, itemId, min, max, category, chance FROM droplist WHERE mobId=" + npcId + " AND itemId=" + itemId+ " AND category=" + category);
  773. ResultSet dropData = statement.executeQuery();
  774. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  775. TextBuilder replyMSG = new TextBuilder("<html><title>the detail of dropdata: (" + npcId + " " + itemId + " " + category + ")</title>");
  776. replyMSG.append("<body>");
  777. if(dropData.next()){
  778. replyMSG.append("<table>");
  779. replyMSG.append("<tr><td>Appertain of NPC</td><td>"+ NpcTable.getInstance().getTemplate(dropData.getInt("mobId")).name + "</td></tr>");
  780. replyMSG.append("<tr><td>ItemName</td><td>"+ ItemTable.getInstance().getTemplate(dropData.getInt("itemId")).getName() + "(" + dropData.getInt("itemId") + ")</td></tr>");
  781. replyMSG.append("<tr><td>Category</td><td>"+ ((category==-1)?"sweep":Integer.toString(category)) + "</td></tr>");
  782. replyMSG.append("<tr><td>MIN(" + dropData.getInt("min") + ")</td><td><edit var=\"min\" width=80></td></tr>");
  783. replyMSG.append("<tr><td>MAX(" + dropData.getInt("max") + ")</td><td><edit var=\"max\" width=80></td></tr>");
  784. replyMSG.append("<tr><td>CHANCE("+ dropData.getInt("chance") + ")</td><td><edit var=\"chance\" width=80></td></tr>");
  785. replyMSG.append("</table>");
  786. replyMSG.append("<center>");
  787. replyMSG.append("<button value=\"Save Modify\" action=\"bypass -h admin_edit_drop " + npcId + " " + itemId + " " + category +" $min $max $chance\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  788. replyMSG.append("<br><button value=\"DropList\" action=\"bypass -h admin_show_droplist " + dropData.getInt("mobId") +"\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  789. replyMSG.append("</center>");
  790. }
  791. dropData.close();
  792. statement.close();
  793. replyMSG.append("</body></html>");
  794. adminReply.setHtml(replyMSG.toString());
  795. activeChar.sendPacket(adminReply);
  796. }
  797. catch(Exception e){}
  798. finally
  799. {
  800. try { con.close(); } catch (Exception e) {}
  801. }
  802. }
  803. private void showAddDropData(L2PcInstance activeChar, L2NpcTemplate npcData)
  804. {
  805. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  806. TextBuilder replyMSG = new TextBuilder("<html><title>Add dropdata to " + npcData.name + "(" + npcData.npcId + ")</title>");
  807. replyMSG.append("<body>");
  808. replyMSG.append("<table>");
  809. replyMSG.append("<tr><td>Item-Id</td><td><edit var=\"itemId\" width=80></td></tr>");
  810. replyMSG.append("<tr><td>MIN</td><td><edit var=\"min\" width=80></td></tr>");
  811. replyMSG.append("<tr><td>MAX</td><td><edit var=\"max\" width=80></td></tr>");
  812. replyMSG.append("<tr><td>CATEGORY(sweep=-1)</td><td><edit var=\"category\" width=80></td></tr>");
  813. replyMSG.append("<tr><td>CHANCE(0-1000000)</td><td><edit var=\"chance\" width=80></td></tr>");
  814. replyMSG.append("</table>");
  815. replyMSG.append("<center>");
  816. replyMSG.append("<button value=\"SAVE\" action=\"bypass -h admin_add_drop " + npcData.npcId + " $itemId $category $min $max $chance\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  817. replyMSG.append("<br><button value=\"DropList\" action=\"bypass -h admin_show_droplist " + npcData.npcId +"\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  818. replyMSG.append("</center>");
  819. replyMSG.append("</body></html>");
  820. adminReply.setHtml(replyMSG.toString());
  821. activeChar.sendPacket(adminReply);
  822. }
  823. private void updateDropData(L2PcInstance activeChar, int npcId, int itemId, int min, int max, int category, int chance)
  824. {
  825. java.sql.Connection con = null;
  826. try
  827. {
  828. con = L2DatabaseFactory.getInstance().getConnection();
  829. PreparedStatement statement = con.prepareStatement("UPDATE droplist SET min=?, max=?, chance=? WHERE mobId=? AND itemId=? AND category=?");
  830. statement.setInt(1, min);
  831. statement.setInt(2, max);
  832. statement.setInt(3, chance);
  833. statement.setInt(4, npcId);
  834. statement.setInt(5, itemId);
  835. statement.setInt(6, category);
  836. statement.execute();
  837. statement.close();
  838. PreparedStatement statement2 = con.prepareStatement("SELECT mobId FROM droplist WHERE mobId=? AND itemId=? AND category=?");
  839. statement2.setInt(1, npcId);
  840. statement2.setInt(2, itemId);
  841. statement2.setInt(3, category);
  842. ResultSet npcIdRs = statement2.executeQuery();
  843. if(npcIdRs.next()) npcId = npcIdRs.getInt("mobId");
  844. npcIdRs.close();
  845. statement2.close();
  846. if(npcId > 0)
  847. {
  848. reLoadNpcDropList(npcId);
  849. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  850. TextBuilder replyMSG = new TextBuilder("<html><title>Drop data modify complete!</title>");
  851. replyMSG.append("<body>");
  852. replyMSG.append("<center><button value=\"DropList\" action=\"bypass -h admin_show_droplist "+ npcId + "\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center>");
  853. replyMSG.append("</body></html>");
  854. adminReply.setHtml(replyMSG.toString());
  855. activeChar.sendPacket(adminReply);
  856. }
  857. else
  858. activeChar.sendMessage("unknown error!");
  859. }
  860. catch(Exception e){ e.printStackTrace(); }
  861. finally
  862. {
  863. try { con.close(); } catch (Exception e) {}
  864. }
  865. }
  866. private void addDropData(L2PcInstance activeChar, int npcId, int itemId, int min, int max, int category, int chance)
  867. {
  868. java.sql.Connection con = null;
  869. try
  870. {
  871. con = L2DatabaseFactory.getInstance().getConnection();
  872. PreparedStatement statement = con.prepareStatement("INSERT INTO droplist(mobId, itemId, min, max, category, chance) values(?,?,?,?,?,?)");
  873. statement.setInt(1, npcId);
  874. statement.setInt(2, itemId);
  875. statement.setInt(3, min);
  876. statement.setInt(4, max);
  877. statement.setInt(5, category);
  878. statement.setInt(6, chance);
  879. statement.execute();
  880. statement.close();
  881. reLoadNpcDropList(npcId);
  882. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  883. TextBuilder replyMSG = new TextBuilder("<html><title>Add drop data complete!</title>");
  884. replyMSG.append("<body>");
  885. replyMSG.append("<center><button value=\"Continue add\" action=\"bypass -h admin_add_drop "+ npcId + "\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  886. replyMSG.append("<br><br><button value=\"DropList\" action=\"bypass -h admin_show_droplist "+ npcId + "\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  887. replyMSG.append("</center></body></html>");
  888. adminReply.setHtml(replyMSG.toString());
  889. activeChar.sendPacket(adminReply);
  890. }
  891. catch(Exception e){}
  892. finally
  893. {
  894. try { con.close(); } catch (Exception e) {}
  895. }
  896. }
  897. private void deleteDropData(L2PcInstance activeChar, int npcId, int itemId, int category)
  898. {
  899. java.sql.Connection con = null;
  900. try
  901. {
  902. con = L2DatabaseFactory.getInstance().getConnection();
  903. if(npcId > 0)
  904. {
  905. PreparedStatement statement2 = con.prepareStatement("DELETE FROM droplist WHERE mobId=? AND itemId=? AND category=?");
  906. statement2.setInt(1, npcId);
  907. statement2.setInt(2, itemId);
  908. statement2.setInt(3, category);
  909. statement2.execute();
  910. statement2.close();
  911. reLoadNpcDropList(npcId);
  912. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  913. TextBuilder replyMSG = new TextBuilder("<html><title>Delete drop data(" + npcId+", "+ itemId+", "+ category + ")complete</title>");
  914. replyMSG.append("<body>");
  915. replyMSG.append("<center><button value=\"DropList\" action=\"bypass -h admin_show_droplist "+ npcId + "\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center>");
  916. replyMSG.append("</body></html>");
  917. adminReply.setHtml(replyMSG.toString());
  918. activeChar.sendPacket(adminReply);
  919. }
  920. }
  921. catch(Exception e){}
  922. finally
  923. {
  924. try { con.close(); } catch (Exception e) {}
  925. }
  926. }
  927. private void reLoadNpcDropList(int npcId)
  928. {
  929. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  930. if (npcData == null)
  931. return;
  932. // reset the drop lists
  933. npcData.clearAllDropData();
  934. // get the drops
  935. java.sql.Connection con = null;
  936. try
  937. {
  938. con = L2DatabaseFactory.getInstance().getConnection();
  939. L2DropData dropData = null;
  940. npcData.clearAllDropData();
  941. PreparedStatement statement = con.prepareStatement("SELECT " + L2DatabaseFactory.getInstance().safetyString(new String[] {"mobId", "itemId", "min", "max", "category", "chance"}) + " FROM droplist WHERE mobId=?");
  942. statement.setInt(1, npcId);
  943. ResultSet dropDataList = statement.executeQuery();
  944. while(dropDataList.next())
  945. {
  946. dropData = new L2DropData();
  947. dropData.setItemId(dropDataList.getInt("itemId"));
  948. dropData.setMinDrop(dropDataList.getInt("min"));
  949. dropData.setMaxDrop(dropDataList.getInt("max"));
  950. dropData.setChance(dropDataList.getInt("chance"));
  951. int category = dropDataList.getInt("category");
  952. npcData.addDropData(dropData, category);
  953. }
  954. dropDataList.close();
  955. statement.close();
  956. }
  957. catch(Exception e){}
  958. finally
  959. {
  960. try { con.close(); } catch (Exception e) {}
  961. }
  962. }
  963. }