AdminEditNpc.java 41 KB

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