AdminEditNpc.java 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  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 handlers.admincommandhandlers;
  16. import java.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.sql.ResultSet;
  19. import java.util.Iterator;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.Set;
  23. import java.util.StringTokenizer;
  24. import java.util.logging.Level;
  25. import java.util.logging.Logger;
  26. import javolution.util.FastMap;
  27. import com.l2jserver.Config;
  28. import com.l2jserver.L2DatabaseFactory;
  29. import com.l2jserver.gameserver.TradeController;
  30. import com.l2jserver.gameserver.cache.HtmCache;
  31. import com.l2jserver.gameserver.datatables.ItemTable;
  32. import com.l2jserver.gameserver.datatables.MerchantPriceConfigTable.MerchantPriceConfig;
  33. import com.l2jserver.gameserver.datatables.NpcTable;
  34. import com.l2jserver.gameserver.datatables.SkillTable;
  35. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  36. import com.l2jserver.gameserver.model.L2DropCategory;
  37. import com.l2jserver.gameserver.model.L2DropData;
  38. import com.l2jserver.gameserver.model.L2Object;
  39. import com.l2jserver.gameserver.model.L2Skill;
  40. import com.l2jserver.gameserver.model.L2TradeList;
  41. import com.l2jserver.gameserver.model.L2TradeList.L2TradeItem;
  42. import com.l2jserver.gameserver.model.actor.L2Npc;
  43. import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
  44. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  45. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  46. import com.l2jserver.gameserver.templates.StatsSet;
  47. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  48. import com.l2jserver.gameserver.templates.item.L2Item;
  49. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  50. import com.l2jserver.util.StringUtil;
  51. /**
  52. * @author terry
  53. * con.close() change by Zoey76 24/02/2011
  54. */
  55. public class AdminEditNpc implements IAdminCommandHandler
  56. {
  57. private static Logger _log = Logger.getLogger(AdminEditNpc.class.getName());
  58. private final static int PAGE_LIMIT = 20;
  59. private static final String[] ADMIN_COMMANDS =
  60. {
  61. "admin_edit_npc",
  62. "admin_save_npc",
  63. "admin_show_droplist",
  64. "admin_edit_drop",
  65. "admin_add_drop",
  66. "admin_del_drop",
  67. "admin_showShop",
  68. "admin_showShopList",
  69. "admin_addShopItem",
  70. "admin_delShopItem",
  71. "admin_editShopItem",
  72. "admin_close_window",
  73. "admin_show_skilllist_npc",
  74. "admin_add_skill_npc",
  75. "admin_edit_skill_npc",
  76. "admin_del_skill_npc",
  77. "admin_log_npc_spawn"
  78. };
  79. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  80. {
  81. //TODO: Tokenize and protect arguments parsing. Externalize HTML.
  82. if (command.startsWith("admin_showShop "))
  83. {
  84. String[] args = command.split(" ");
  85. if (args.length > 1)
  86. showShop(activeChar, Integer.parseInt(command.split(" ")[1]));
  87. }
  88. else if (command.startsWith("admin_log_npc_spawn"))
  89. {
  90. L2Object target = activeChar.getTarget();
  91. if (target instanceof L2Npc)
  92. {
  93. L2Npc npc = (L2Npc) target;
  94. _log.info("('',1,"+npc.getNpcId()+","+npc.getX()+","+npc.getY()+","+npc.getZ()+",0,0,"+npc.getHeading()+",60,0,0),");
  95. }
  96. }
  97. else if (command.startsWith("admin_showShopList "))
  98. {
  99. String[] args = command.split(" ");
  100. if (args.length > 2)
  101. showShopList(activeChar, Integer.parseInt(command.split(" ")[1]), Integer.parseInt(command.split(" ")[2]));
  102. }
  103. else if (command.startsWith("admin_edit_npc "))
  104. {
  105. try
  106. {
  107. String[] commandSplit = command.split(" ");
  108. int npcId = Integer.parseInt(commandSplit[1]);
  109. L2NpcTemplate npc = NpcTable.getInstance().getTemplate(npcId);
  110. showNpcProperty(activeChar, npc);
  111. }
  112. catch (Exception e)
  113. {
  114. activeChar.sendMessage("Wrong usage: //edit_npc <npcId>");
  115. }
  116. }
  117. else if (command.startsWith("admin_show_droplist "))
  118. {
  119. StringTokenizer st = new StringTokenizer(command, " ");
  120. st.nextToken();
  121. try
  122. {
  123. int npcId = Integer.parseInt(st.nextToken());
  124. int page = 1;
  125. if (st.hasMoreTokens())
  126. page = Integer.parseInt(st.nextToken());
  127. showNpcDropList(activeChar, npcId, page);
  128. }
  129. catch (Exception e)
  130. {
  131. activeChar.sendMessage("Usage: //show_droplist <npc_id> [<page>]");
  132. }
  133. }
  134. else if (command.startsWith("admin_addShopItem "))
  135. {
  136. String[] args = command.split(" ");
  137. if (args.length > 1)
  138. addShopItem(activeChar, args);
  139. }
  140. else if (command.startsWith("admin_delShopItem "))
  141. {
  142. String[] args = command.split(" ");
  143. if (args.length > 2)
  144. delShopItem(activeChar, args);
  145. }
  146. else if (command.startsWith("admin_editShopItem "))
  147. {
  148. String[] args = command.split(" ");
  149. if (args.length > 2)
  150. editShopItem(activeChar, args);
  151. }
  152. else if (command.startsWith("admin_save_npc "))
  153. {
  154. try
  155. {
  156. saveNpcProperty(activeChar, command);
  157. }
  158. catch (StringIndexOutOfBoundsException e)
  159. {
  160. }
  161. }
  162. else if (command.startsWith("admin_edit_drop "))
  163. {
  164. int npcId = -1, itemId = 0, category = -1000;
  165. try
  166. {
  167. StringTokenizer st = new StringTokenizer(command.substring(16).trim());
  168. if (st.countTokens() == 3)
  169. {
  170. try
  171. {
  172. npcId = Integer.parseInt(st.nextToken());
  173. itemId = Integer.parseInt(st.nextToken());
  174. category = Integer.parseInt(st.nextToken());
  175. showEditDropData(activeChar, npcId, itemId, category);
  176. }
  177. catch (Exception e)
  178. {
  179. _log.log(Level.WARNING, "", e);
  180. }
  181. }
  182. else if (st.countTokens() == 6)
  183. {
  184. try
  185. {
  186. npcId = Integer.parseInt(st.nextToken());
  187. itemId = Integer.parseInt(st.nextToken());
  188. category = Integer.parseInt(st.nextToken());
  189. int min = Integer.parseInt(st.nextToken());
  190. int max = Integer.parseInt(st.nextToken());
  191. int chance = Integer.parseInt(st.nextToken());
  192. updateDropData(activeChar, npcId, itemId, min, max, category, chance);
  193. }
  194. catch (Exception e)
  195. {
  196. _log.fine("admin_edit_drop parameters error: " + command);
  197. }
  198. }
  199. else
  200. activeChar.sendMessage("Usage: //edit_drop <npc_id> <item_id> <category> [<min> <max> <chance>]");
  201. }
  202. catch (StringIndexOutOfBoundsException e)
  203. {
  204. activeChar.sendMessage("Usage: //edit_drop <npc_id> <item_id> <category> [<min> <max> <chance>]");
  205. }
  206. }
  207. else if (command.startsWith("admin_add_drop "))
  208. {
  209. int npcId = -1;
  210. try
  211. {
  212. StringTokenizer st = new StringTokenizer(command.substring(15).trim());
  213. if (st.countTokens() == 1)
  214. {
  215. try
  216. {
  217. String[] input = command.substring(15).split(" ");
  218. if (input.length < 1)
  219. return true;
  220. npcId = Integer.parseInt(input[0]);
  221. }
  222. catch (Exception e)
  223. {
  224. }
  225. if (npcId > 0)
  226. {
  227. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  228. showAddDropData(activeChar, npcData);
  229. }
  230. }
  231. else if (st.countTokens() == 6)
  232. {
  233. try
  234. {
  235. npcId = Integer.parseInt(st.nextToken());
  236. int itemId = Integer.parseInt(st.nextToken());
  237. int category = Integer.parseInt(st.nextToken());
  238. int min = Integer.parseInt(st.nextToken());
  239. int max = Integer.parseInt(st.nextToken());
  240. int chance = Integer.parseInt(st.nextToken());
  241. addDropData(activeChar, npcId, itemId, min, max, category, chance);
  242. }
  243. catch (Exception e)
  244. {
  245. _log.fine("admin_add_drop parameters error: " + command);
  246. }
  247. }
  248. else
  249. activeChar.sendMessage("Usage: //add_drop <npc_id> [<item_id> <category> <min> <max> <chance>]");
  250. }
  251. catch (StringIndexOutOfBoundsException e)
  252. {
  253. activeChar.sendMessage("Usage: //add_drop <npc_id> [<item_id> <category> <min> <max> <chance>]");
  254. }
  255. }
  256. else if (command.startsWith("admin_del_drop "))
  257. {
  258. StringTokenizer st = new StringTokenizer(command, " ");
  259. st.nextToken();
  260. try
  261. {
  262. int npcId = Integer.parseInt(st.nextToken());
  263. int itemId = Integer.parseInt(st.nextToken());
  264. int category = Integer.parseInt(st.nextToken());
  265. boolean confirmed = false;
  266. if (st.hasMoreTokens())
  267. confirmed = true;
  268. deleteDropData(activeChar, npcId, itemId, category, confirmed);
  269. }
  270. catch (Exception e)
  271. {
  272. activeChar.sendMessage("Usage: //del_drop <npc_id> <item_id> <category>");
  273. }
  274. }
  275. else if (command.startsWith("admin_show_skilllist_npc "))
  276. {
  277. StringTokenizer st = new StringTokenizer(command, " ");
  278. st.nextToken();
  279. try
  280. {
  281. int npcId = Integer.parseInt(st.nextToken());
  282. int page = 0;
  283. if (st.hasMoreTokens())
  284. page = Integer.parseInt(st.nextToken());
  285. showNpcSkillList(activeChar, npcId, page);
  286. }
  287. catch (Exception e)
  288. {
  289. activeChar.sendMessage("Usage: //show_skilllist_npc <npc_id> <page>");
  290. }
  291. }
  292. else if (command.startsWith("admin_edit_skill_npc "))
  293. {
  294. try
  295. {
  296. StringTokenizer st = new StringTokenizer(command, " ");
  297. st.nextToken();
  298. int npcId = Integer.parseInt(st.nextToken());
  299. int skillId = Integer.parseInt(st.nextToken());
  300. if (!st.hasMoreTokens())
  301. showNpcSkillEdit(activeChar, npcId, skillId);
  302. else
  303. {
  304. int level = Integer.parseInt(st.nextToken());
  305. updateNpcSkillData(activeChar, npcId, skillId, level);
  306. }
  307. }
  308. catch (Exception e)
  309. {
  310. activeChar.sendMessage("Usage: //edit_skill_npc <npc_id> <item_id> [<level>]");
  311. }
  312. }
  313. else if (command.startsWith("admin_add_skill_npc "))
  314. {
  315. try
  316. {
  317. StringTokenizer st = new StringTokenizer(command, " ");
  318. st.nextToken();
  319. int npcId = Integer.parseInt(st.nextToken());
  320. if (!st.hasMoreTokens())
  321. {
  322. showNpcSkillAdd(activeChar, npcId);
  323. }
  324. else
  325. {
  326. int skillId = Integer.parseInt(st.nextToken());
  327. int level = Integer.parseInt(st.nextToken());
  328. addNpcSkillData(activeChar, npcId, skillId, level);
  329. }
  330. }
  331. catch (Exception e)
  332. {
  333. activeChar.sendMessage("Usage: //add_skill_npc <npc_id> [<skill_id> <level>]");
  334. }
  335. }
  336. else if (command.startsWith("admin_del_skill_npc "))
  337. {
  338. try
  339. {
  340. StringTokenizer st = new StringTokenizer(command, " ");
  341. st.nextToken();
  342. int npcId = Integer.parseInt(st.nextToken());
  343. int skillId = Integer.parseInt(st.nextToken());
  344. deleteNpcSkillData(activeChar, npcId, skillId);
  345. }
  346. catch (Exception e)
  347. {
  348. activeChar.sendMessage("Usage: //del_skill_npc <npc_id> <skill_id>");
  349. }
  350. }
  351. return true;
  352. }
  353. private void editShopItem(L2PcInstance activeChar, String[] args)
  354. {
  355. int tradeListID = Integer.parseInt(args[1]);
  356. int itemID = Integer.parseInt(args[2]);
  357. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  358. L2Item item = ItemTable.getInstance().getTemplate(itemID);
  359. if (tradeList.getPriceForItemId(itemID) < 0)
  360. return;
  361. if (args.length > 3)
  362. {
  363. long price = Long.parseLong(args[3]);
  364. int order = findOrderTradeList(itemID, tradeList.getPriceForItemId(itemID), tradeListID);
  365. tradeList.replaceItem(itemID, Long.parseLong(args[3]));
  366. updateTradeList(itemID, price, tradeListID, order);
  367. activeChar.sendMessage("Updated price for " + item.getName() + " in Trade List " + tradeListID);
  368. showShopList(activeChar, tradeListID, 1);
  369. return;
  370. }
  371. final String replyMSG = StringUtil.concat("<html><title>Merchant Shop Item Edit</title><body><center><font color=\"LEVEL\">",
  372. NpcTable.getInstance().getTemplate(Integer.parseInt(tradeList.getNpcId())).getName(),
  373. " (",
  374. tradeList.getNpcId(),
  375. ") -> ",
  376. Integer.toString(tradeListID),
  377. "</font></center><table width=\"100%\"><tr><td>Item</td><td>",
  378. item.getName(),
  379. " (",
  380. Integer.toString(item.getItemId()),
  381. ")",
  382. "</td></tr><tr><td>Price (",
  383. String.valueOf(tradeList.getPriceForItemId(itemID)),
  384. ")</td><td><edit var=\"price\" width=80></td></tr></table><center><br><button value=\"Save\" action=\"bypass -h admin_editShopItem ",
  385. String.valueOf(tradeListID),
  386. " ",
  387. String.valueOf(itemID),
  388. " $price\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Back to Shop List\" action=\"bypass -h admin_showShopList ",
  389. String.valueOf(tradeListID),
  390. " 1\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  391. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  392. adminReply.setHtml(replyMSG);
  393. activeChar.sendPacket(adminReply);
  394. }
  395. private void delShopItem(L2PcInstance activeChar, String[] args)
  396. {
  397. int tradeListID = Integer.parseInt(args[1]);
  398. int itemID = Integer.parseInt(args[2]);
  399. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  400. if (tradeList.getPriceForItemId(itemID) < 0)
  401. return;
  402. if (args.length > 3)
  403. {
  404. int order = findOrderTradeList(itemID, tradeList.getPriceForItemId(itemID), tradeListID);
  405. tradeList.removeItem(itemID);
  406. deleteTradeList(tradeListID, order);
  407. activeChar.sendMessage("Deleted " + ItemTable.getInstance().getTemplate(itemID).getName() + " from Trade List " + tradeListID);
  408. showShopList(activeChar, tradeListID, 1);
  409. return;
  410. }
  411. final String replyMSG = StringUtil.concat("<html><title>Merchant Shop Item Delete</title><body><br>Delete entry in trade list ",
  412. String.valueOf(tradeListID),
  413. "<table width=\"100%\"><tr><td>Item</td><td>",
  414. ItemTable.getInstance().getTemplate(itemID).getName(),
  415. " (",
  416. Integer.toString(itemID),
  417. ")</td></tr><tr><td>Price</td><td>",
  418. String.valueOf(tradeList.getPriceForItemId(itemID)),
  419. "</td></tr></table><center><br><button value=\"Delete\" action=\"bypass -h admin_delShopItem ",
  420. String.valueOf(tradeListID),
  421. " ",
  422. String.valueOf(itemID),
  423. " 1\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Back to Shop List\" action=\"bypass -h admin_showShopList ",
  424. String.valueOf(tradeListID),
  425. " 1\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  426. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  427. adminReply.setHtml(replyMSG);
  428. activeChar.sendPacket(adminReply);
  429. }
  430. private void addShopItem(L2PcInstance activeChar, String[] args)
  431. {
  432. int tradeListID = Integer.parseInt(args[1]);
  433. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  434. if (tradeList == null)
  435. {
  436. activeChar.sendMessage("TradeList not found!");
  437. return;
  438. }
  439. if (args.length > 3)
  440. {
  441. int order = tradeList.getItems().size() + 1; // last item order + 1
  442. int itemID = Integer.parseInt(args[2]);
  443. long price = Long.parseLong(args[3]);
  444. L2TradeItem newItem = new L2TradeItem(tradeListID, itemID);
  445. newItem.setPrice(price);
  446. newItem.setMaxCount(-1);
  447. tradeList.addItem(newItem);
  448. boolean stored = storeTradeList(itemID, price, tradeListID, order);
  449. if (stored)
  450. activeChar.sendMessage("Added " + ItemTable.getInstance().getTemplate(itemID).getName() + " to Trade List " + tradeList.getListId());
  451. else
  452. activeChar.sendMessage("Could not add " + ItemTable.getInstance().getTemplate(itemID).getName() + " to Trade List " + tradeList.getListId() + "!");
  453. showShopList(activeChar, tradeListID, 1);
  454. return;
  455. }
  456. final String replyMSG = StringUtil.concat("<html><title>Merchant Shop Item Add</title><body><br>Add a new entry in merchantList.<table width=\"100%\"><tr><td>ItemID</td><td><edit var=\"itemID\" width=80></td></tr><tr><td>Price</td><td><edit var=\"price\" width=80></td></tr></table><center><br><button value=\"Add\" action=\"bypass -h admin_addShopItem ",
  457. String.valueOf(tradeListID),
  458. " $itemID $price\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Back to Shop List\" action=\"bypass -h admin_showShopList ",
  459. String.valueOf(tradeListID),
  460. " 1\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  461. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  462. adminReply.setHtml(replyMSG);
  463. activeChar.sendPacket(adminReply);
  464. }
  465. private void showShopList(L2PcInstance activeChar, int tradeListID, int page)
  466. {
  467. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  468. if (page > tradeList.getItems().size() / PAGE_LIMIT + 1 || page < 1)
  469. return;
  470. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  471. adminReply.setHtml(itemListHtml(tradeList, page));
  472. activeChar.sendPacket(adminReply);
  473. }
  474. private String itemListHtml(L2TradeList tradeList, int page)
  475. {
  476. final StringBuilder replyMSG = new StringBuilder();
  477. int max = tradeList.getItems().size() / PAGE_LIMIT;
  478. if (tradeList.getItems().size() > PAGE_LIMIT * max)
  479. max++;
  480. StringUtil.append(replyMSG, "<html><title>Merchant Shop List Page: ",
  481. String.valueOf(page),
  482. " of ",
  483. Integer.toString(max),
  484. "</title><body><br><center><font color=\"LEVEL\">",
  485. NpcTable.getInstance().getTemplate(Integer.parseInt(tradeList.getNpcId())).getName(),
  486. " (",
  487. tradeList.getNpcId(),
  488. ") Shop ID: ",
  489. Integer.toString(tradeList.getListId()),
  490. "</font></center><table width=300 bgcolor=666666><tr>");
  491. for (int x = 0; x < max; x++)
  492. {
  493. int pagenr = x + 1;
  494. if (page == pagenr)
  495. {
  496. replyMSG.append("<td>Page ");
  497. replyMSG.append(pagenr);
  498. replyMSG.append("</td>");
  499. }
  500. else
  501. {
  502. replyMSG.append("<td><a action=\"bypass -h admin_showShopList ");
  503. replyMSG.append(tradeList.getListId());
  504. replyMSG.append(" ");
  505. replyMSG.append(x+1);
  506. replyMSG.append("\"> Page ");
  507. replyMSG.append(pagenr);
  508. replyMSG.append(" </a></td>");
  509. }
  510. }
  511. replyMSG.append("</tr></table><table width=\"100%\"><tr><td width=150>Item</td><td width=60>Price</td><td width=40>Delete</td></tr>");
  512. int start = ((page - 1) * PAGE_LIMIT);
  513. int end = Math.min(((page - 1) * PAGE_LIMIT) + PAGE_LIMIT, tradeList.getItems().size());
  514. //System.out.println("page: " + page + "; tradeList.getItems().size(): " + tradeList.getItems().size() + "; start: " + start + "; end: " + end + "; max: " + max);
  515. for (L2TradeItem item : tradeList.getItems(start, end))
  516. {
  517. StringUtil.append(replyMSG, "<tr><td><a action=\"bypass -h admin_editShopItem ",
  518. String.valueOf(tradeList.getListId()),
  519. " ",
  520. String.valueOf(item.getItemId()),
  521. "\">",
  522. ItemTable.getInstance().getTemplate(item.getItemId()).getName(),
  523. "</a></td><td>",
  524. String.valueOf(item.getPrice()),
  525. "</td><td><a action=\"bypass -h admin_delShopItem ",
  526. String.valueOf(tradeList.getListId()),
  527. " ",
  528. String.valueOf(item.getItemId()),
  529. "\">Delete</a></td></tr>");
  530. }
  531. StringUtil.append(replyMSG, "<tr><td><br><br></td><td> </td><td> </td></tr><tr>");
  532. StringUtil.append(replyMSG, "</tr></table><center><br><button value=\"Add Shop Item\" action=\"bypass -h admin_addShopItem ",
  533. String.valueOf(tradeList.getListId()),
  534. "\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  535. return replyMSG.toString();
  536. }
  537. private void showShop(L2PcInstance activeChar, int merchantID)
  538. {
  539. List<L2TradeList> tradeLists = TradeController.getInstance().getBuyListByNpcId(merchantID);
  540. if (tradeLists == null)
  541. {
  542. activeChar.sendMessage("Unknown npc template Id: " + merchantID);
  543. return;
  544. }
  545. final StringBuilder replyMSG = new StringBuilder();
  546. StringUtil.append(replyMSG, "<html><title>Merchant Shop Lists</title><body>");
  547. if (activeChar.getTarget() instanceof L2MerchantInstance)
  548. {
  549. MerchantPriceConfig mpc = ((L2MerchantInstance) activeChar.getTarget()).getMpc();
  550. StringUtil.append(replyMSG,
  551. "<br>NPC: ",
  552. activeChar.getTarget().getName(),
  553. " (",
  554. Integer.toString(merchantID),
  555. ") <br>Price Config: ",
  556. mpc.getName(),
  557. ", ",
  558. Integer.toString(mpc.getBaseTax()),
  559. "% / ",
  560. Integer.toString(mpc.getTotalTax()),
  561. "%");
  562. }
  563. StringUtil.append(replyMSG, "<table width=\"100%\">");
  564. for (L2TradeList tradeList : tradeLists)
  565. {
  566. if (tradeList != null)
  567. {
  568. StringUtil.append(replyMSG, "<tr><td><a action=\"bypass -h admin_showShopList ",
  569. String.valueOf(tradeList.getListId()),
  570. " 1\">Merchant List ID ",
  571. String.valueOf(tradeList.getListId()),
  572. "</a></td></tr>");
  573. }
  574. }
  575. StringUtil.append(replyMSG, "</table><center><br><button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  576. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  577. adminReply.setHtml(replyMSG.toString());
  578. activeChar.sendPacket(adminReply);
  579. }
  580. private boolean storeTradeList(int itemID, long price, int tradeListID, int order)
  581. {
  582. Connection con = null;
  583. try
  584. {
  585. con = L2DatabaseFactory.getInstance().getConnection();
  586. String table = "merchant_buylists";
  587. if (Config.CUSTOM_MERCHANT_TABLES)
  588. table = "custom_merchant_buylists";
  589. PreparedStatement stmt = con.prepareStatement("INSERT INTO `" + table + "`(`item_id`,`price`,`shop_id`,`order`) VALUES (?,?,?,?)");
  590. stmt.setInt(1, itemID);
  591. stmt.setLong(2, price);
  592. stmt.setInt(3, tradeListID);
  593. stmt.setInt(4, order);
  594. stmt.execute();
  595. stmt.close();
  596. }
  597. catch (Exception e)
  598. {
  599. _log.warning("Could not store trade list (" + itemID + ", " + price + ", " + tradeListID + ", " + order + "): " + e);
  600. return false;
  601. }
  602. finally
  603. {
  604. L2DatabaseFactory.close(con);
  605. }
  606. return true;
  607. }
  608. private void updateTradeList(int itemID, long price, int tradeListID, int order)
  609. {
  610. Connection con = null;
  611. try
  612. {
  613. con = L2DatabaseFactory.getInstance().getConnection();
  614. int updated = 0;
  615. if (Config.CUSTOM_MERCHANT_TABLES)
  616. {
  617. PreparedStatement stmt = con.prepareStatement("UPDATE `custom_merchant_buylists` SET `price` = ? WHERE `shop_id` = ? AND `order` = ?");
  618. stmt.setLong(1, price);
  619. stmt.setInt(2, tradeListID);
  620. stmt.setInt(3, order);
  621. updated = stmt.executeUpdate();
  622. stmt.close();
  623. }
  624. if (updated == 0)
  625. {
  626. PreparedStatement stmt = con.prepareStatement("UPDATE `merchant_buylists` SET `price` = ? WHERE `shop_id` = ? AND `order` = ?");
  627. stmt.setLong(1, price);
  628. stmt.setInt(2, tradeListID);
  629. stmt.setInt(3, order);
  630. updated = stmt.executeUpdate();
  631. stmt.close();
  632. }
  633. }
  634. catch (Exception e)
  635. {
  636. _log.warning("Could not update trade list (" + itemID + ", " + price + ", " + tradeListID + ", " + order + "): " + e);
  637. }
  638. finally
  639. {
  640. L2DatabaseFactory.close(con);
  641. }
  642. }
  643. private void deleteTradeList(int tradeListID, int order)
  644. {
  645. Connection con = null;
  646. try
  647. {
  648. con = L2DatabaseFactory.getInstance().getConnection();
  649. int updated = 0;
  650. if (Config.CUSTOM_MERCHANT_TABLES)
  651. {
  652. PreparedStatement stmt = con.prepareStatement("DELETE FROM `custom_merchant_buylists` WHERE `shop_id` = ? AND `order` = ?");
  653. stmt.setInt(1, tradeListID);
  654. stmt.setInt(2, order);
  655. updated = stmt.executeUpdate();
  656. stmt.close();
  657. }
  658. if (updated == 0)
  659. {
  660. PreparedStatement stmt = con.prepareStatement("DELETE FROM `merchant_buylists` WHERE `shop_id` = ? AND `order` = ?");
  661. stmt.setInt(1, tradeListID);
  662. stmt.setInt(2, order);
  663. updated = stmt.executeUpdate();
  664. stmt.close();
  665. }
  666. }
  667. catch (Exception e)
  668. {
  669. _log.warning("Could not delete trade list (" + tradeListID + ", " + order + "): " + e);
  670. }
  671. finally
  672. {
  673. L2DatabaseFactory.close(con);
  674. }
  675. }
  676. private int findOrderTradeList(int itemID, long price, int tradeListID)
  677. {
  678. Connection con = null;
  679. int order = -1;
  680. try
  681. {
  682. con = L2DatabaseFactory.getInstance().getConnection();
  683. PreparedStatement stmt = con.prepareStatement("SELECT `order` FROM `merchant_buylists` WHERE `shop_id` = ? AND `item_id` = ? AND `price` = ?");
  684. stmt.setInt(1, tradeListID);
  685. stmt.setInt(2, itemID);
  686. stmt.setLong(3, price);
  687. ResultSet rs = stmt.executeQuery();
  688. if (rs.first())
  689. order = rs.getInt("order");
  690. stmt.close();
  691. rs.close();
  692. }
  693. catch (Exception e)
  694. {
  695. _log.warning("Could not get order for (" + itemID + ", " + price + ", " + tradeListID + "): " + e);
  696. }
  697. finally
  698. {
  699. L2DatabaseFactory.close(con);
  700. }
  701. return order;
  702. }
  703. public String[] getAdminCommandList()
  704. {
  705. return ADMIN_COMMANDS;
  706. }
  707. private void showNpcProperty(L2PcInstance activeChar, L2NpcTemplate npc)
  708. {
  709. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  710. String content = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/editnpc.htm");
  711. if (content != null)
  712. {
  713. adminReply.setHtml(content);
  714. adminReply.replace("%npcId%", String.valueOf(npc.npcId));
  715. adminReply.replace("%templateId%", String.valueOf(npc.idTemplate));
  716. adminReply.replace("%name%", npc.name);
  717. adminReply.replace("%serverSideName%", npc.serverSideName == true ? "1" : "0");
  718. adminReply.replace("%title%", npc.title);
  719. adminReply.replace("%serverSideTitle%", npc.serverSideTitle == true ? "1" : "0");
  720. adminReply.replace("%collisionRadius%", String.valueOf(npc.fCollisionRadius));
  721. adminReply.replace("%collisionHeight%", String.valueOf(npc.fCollisionHeight));
  722. adminReply.replace("%level%", String.valueOf(npc.level));
  723. adminReply.replace("%sex%", String.valueOf(npc.sex));
  724. adminReply.replace("%type%", String.valueOf(npc.type));
  725. adminReply.replace("%attackRange%", String.valueOf(npc.baseAtkRange));
  726. adminReply.replace("%hp%", String.valueOf(npc.baseHpMax));
  727. adminReply.replace("%mp%", String.valueOf(npc.baseMpMax));
  728. adminReply.replace("%hpRegen%", String.valueOf(npc.baseHpReg));
  729. adminReply.replace("%mpRegen%", String.valueOf(npc.baseMpReg));
  730. adminReply.replace("%str%", String.valueOf(npc.baseSTR));
  731. adminReply.replace("%con%", String.valueOf(npc.baseCON));
  732. adminReply.replace("%dex%", String.valueOf(npc.baseDEX));
  733. adminReply.replace("%int%", String.valueOf(npc.baseINT));
  734. adminReply.replace("%wit%", String.valueOf(npc.baseWIT));
  735. adminReply.replace("%men%", String.valueOf(npc.baseMEN));
  736. adminReply.replace("%exp%", String.valueOf(npc.rewardExp));
  737. adminReply.replace("%sp%", String.valueOf(npc.rewardSp));
  738. adminReply.replace("%pAtk%", String.valueOf(npc.basePAtk));
  739. adminReply.replace("%pDef%", String.valueOf(npc.basePDef));
  740. adminReply.replace("%mAtk%", String.valueOf(npc.baseMAtk));
  741. adminReply.replace("%mDef%", String.valueOf(npc.baseMDef));
  742. adminReply.replace("%pAtkSpd%", String.valueOf(npc.basePAtkSpd));
  743. adminReply.replace("%aggro%", String.valueOf(npc.aggroRange));
  744. adminReply.replace("%mAtkSpd%", String.valueOf(npc.baseMAtkSpd));
  745. adminReply.replace("%rHand%", String.valueOf(npc.rhand));
  746. adminReply.replace("%lHand%", String.valueOf(npc.lhand));
  747. adminReply.replace("%enchant%", String.valueOf(npc.enchantEffect));
  748. adminReply.replace("%walkSpd%", String.valueOf(npc.baseWalkSpd));
  749. adminReply.replace("%runSpd%", String.valueOf(npc.baseRunSpd));
  750. adminReply.replace("%factionId%", npc.getAIDataStatic().getClan() == null ? "" : npc.getAIDataStatic().getClan());
  751. adminReply.replace("%factionRange%", String.valueOf(npc.getAIDataStatic().getClanRange()));
  752. }
  753. else
  754. adminReply.setHtml("<html><head><body>File not found: data/html/admin/editnpc.htm</body></html>");
  755. activeChar.sendPacket(adminReply);
  756. }
  757. private void saveNpcProperty(L2PcInstance activeChar, String command)
  758. {
  759. String[] commandSplit = command.split(" ");
  760. if (commandSplit.length < 4)
  761. return;
  762. StatsSet newNpcData = new StatsSet();
  763. try
  764. {
  765. newNpcData.set("npcId", commandSplit[1]);
  766. String statToSet = commandSplit[2];
  767. String value = commandSplit[3];
  768. if (commandSplit.length > 4)
  769. {
  770. for (int i = 0; i < commandSplit.length - 3; i++)
  771. value += " " + commandSplit[i + 4];
  772. }
  773. if (statToSet.equals("templateId"))
  774. newNpcData.set("idTemplate", Integer.parseInt(value));
  775. else if (statToSet.equals("name"))
  776. newNpcData.set("name", value);
  777. else if (statToSet.equals("serverSideName"))
  778. newNpcData.set("serverSideName", Integer.parseInt(value));
  779. else if (statToSet.equals("title"))
  780. newNpcData.set("title", value);
  781. else if (statToSet.equals("serverSideTitle"))
  782. newNpcData.set("serverSideTitle", Integer.parseInt(value) == 1 ? 1 : 0);
  783. else if (statToSet.equals("collisionRadius"))
  784. newNpcData.set("collision_radius", Integer.parseInt(value));
  785. else if (statToSet.equals("collisionHeight"))
  786. newNpcData.set("collision_height", Integer.parseInt(value));
  787. else if (statToSet.equals("level"))
  788. newNpcData.set("level", Integer.parseInt(value));
  789. else if (statToSet.equals("sex"))
  790. {
  791. int intValue = Integer.parseInt(value);
  792. newNpcData.set("sex", intValue == 0 ? "male" : intValue == 1 ? "female" : "etc");
  793. }
  794. else if (statToSet.equals("type"))
  795. {
  796. Class.forName("com.l2jserver.gameserver.model.actor.instance." + value + "Instance");
  797. newNpcData.set("type", value);
  798. }
  799. else if (statToSet.equals("attackRange"))
  800. newNpcData.set("attackrange", Integer.parseInt(value));
  801. else if (statToSet.equals("hp"))
  802. newNpcData.set("hp", Integer.parseInt(value));
  803. else if (statToSet.equals("mp"))
  804. newNpcData.set("mp", Integer.parseInt(value));
  805. else if (statToSet.equals("hpRegen"))
  806. newNpcData.set("hpreg", Integer.parseInt(value));
  807. else if (statToSet.equals("mpRegen"))
  808. newNpcData.set("mpreg", Integer.parseInt(value));
  809. else if (statToSet.equals("str"))
  810. newNpcData.set("str", Integer.parseInt(value));
  811. else if (statToSet.equals("con"))
  812. newNpcData.set("con", Integer.parseInt(value));
  813. else if (statToSet.equals("dex"))
  814. newNpcData.set("dex", Integer.parseInt(value));
  815. else if (statToSet.equals("int"))
  816. newNpcData.set("int", Integer.parseInt(value));
  817. else if (statToSet.equals("wit"))
  818. newNpcData.set("wit", Integer.parseInt(value));
  819. else if (statToSet.equals("men"))
  820. newNpcData.set("men", Integer.parseInt(value));
  821. else if (statToSet.equals("exp"))
  822. newNpcData.set("exp", Integer.parseInt(value));
  823. else if (statToSet.equals("sp"))
  824. newNpcData.set("sp", Integer.parseInt(value));
  825. else if (statToSet.equals("pAtk"))
  826. newNpcData.set("patk", Integer.parseInt(value));
  827. else if (statToSet.equals("pDef"))
  828. newNpcData.set("pdef", Integer.parseInt(value));
  829. else if (statToSet.equals("mAtk"))
  830. newNpcData.set("matk", Integer.parseInt(value));
  831. else if (statToSet.equals("mDef"))
  832. newNpcData.set("mdef", Integer.parseInt(value));
  833. else if (statToSet.equals("pAtkSpd"))
  834. newNpcData.set("atkspd", Integer.parseInt(value));
  835. else if (statToSet.equals("aggro"))
  836. newNpcData.set("aggro", Integer.parseInt(value));
  837. else if (statToSet.equals("mAtkSpd"))
  838. newNpcData.set("matkspd", Integer.parseInt(value));
  839. else if (statToSet.equals("rHand"))
  840. newNpcData.set("rhand", Integer.parseInt(value));
  841. else if (statToSet.equals("lHand"))
  842. newNpcData.set("lhand", Integer.parseInt(value));
  843. else if (statToSet.equals("armor"))
  844. newNpcData.set("armor", Integer.parseInt(value));
  845. else if (statToSet.equals("enchant"))
  846. newNpcData.set("enchant", Integer.parseInt(value));
  847. else if (statToSet.equals("runSpd"))
  848. newNpcData.set("runspd", Integer.parseInt(value));
  849. else if (statToSet.equals("isUndead"))
  850. newNpcData.set("isUndead", Integer.parseInt(value) == 1 ? 1 : 0);
  851. else if (statToSet.equals("absorbLevel"))
  852. {
  853. int intVal = Integer.parseInt(value);
  854. newNpcData.set("absorb_level", intVal < 0 ? 0 : intVal > 16 ? 0 : intVal);
  855. }
  856. }
  857. catch (Exception e)
  858. {
  859. activeChar.sendMessage("Could not save npc property!");
  860. _log.warning("Error saving new npc value (" + command + "): " + e);
  861. }
  862. NpcTable.getInstance().saveNpc(newNpcData);
  863. int npcId = newNpcData.getInteger("npcId");
  864. NpcTable.getInstance().reloadNpc(npcId);
  865. showNpcProperty(activeChar, NpcTable.getInstance().getTemplate(npcId));
  866. }
  867. private void showNpcDropList(L2PcInstance activeChar, int npcId, int page)
  868. {
  869. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  870. if (npcData == null)
  871. {
  872. activeChar.sendMessage("Unknown npc template id " + npcId);
  873. return;
  874. }
  875. final StringBuilder replyMSG = new StringBuilder(2900);
  876. replyMSG.append("<html><title>Show droplist page ");
  877. replyMSG.append(page);
  878. replyMSG.append("</title><body><br1><center><font color=\"LEVEL\">");
  879. replyMSG.append(npcData.name);
  880. replyMSG.append(" (");
  881. replyMSG.append(npcId);
  882. replyMSG.append(")</font></center><br1><table width=\"100%\" border=0><tr><td width=35>cat.</td><td width=210>item</td><td width=30>type</td><td width=25>del</td></tr>");
  883. int myPage = 1;
  884. int i = 0;
  885. int shown = 0;
  886. boolean hasMore = false;
  887. if (npcData.getDropData() != null)
  888. {
  889. for (L2DropCategory cat : npcData.getDropData())
  890. {
  891. if (shown == PAGE_LIMIT)
  892. {
  893. hasMore = true;
  894. break;
  895. }
  896. for (L2DropData drop : cat.getAllDrops())
  897. {
  898. if (myPage != page)
  899. {
  900. i++;
  901. if (i == PAGE_LIMIT)
  902. {
  903. myPage++;
  904. i = 0;
  905. }
  906. continue;
  907. }
  908. if (shown == PAGE_LIMIT)
  909. {
  910. hasMore = true;
  911. break;
  912. }
  913. replyMSG.append("<tr><td>");
  914. replyMSG.append(cat.getCategoryType());
  915. replyMSG.append("</td><td><a action=\"bypass -h admin_edit_drop ");
  916. replyMSG.append(npcId);
  917. replyMSG.append(" ");
  918. replyMSG.append(drop.getItemId());
  919. replyMSG.append(" ");
  920. replyMSG.append(cat.getCategoryType());
  921. replyMSG.append("\">");
  922. replyMSG.append(ItemTable.getInstance().getTemplate(drop.getItemId()).getName());
  923. replyMSG.append(" (");
  924. replyMSG.append(drop.getItemId());
  925. replyMSG.append(")</a></td><td>");
  926. replyMSG.append((drop.isQuestDrop() ? "Q" : (cat.isSweep() ? "S" : "D")));
  927. replyMSG.append("</td><td><a action=\"bypass -h admin_del_drop ");
  928. replyMSG.append(npcId);
  929. replyMSG.append(" ");
  930. replyMSG.append(drop.getItemId());
  931. replyMSG.append(" ");
  932. replyMSG.append(cat.getCategoryType());
  933. replyMSG.append("\">del</a></td></tr>");
  934. shown++;
  935. }
  936. }
  937. }
  938. replyMSG.append("</table><table width=300 bgcolor=666666 border=0><tr>");
  939. if (page > 1)
  940. {
  941. replyMSG.append("<td width=120><a action=\"bypass -h admin_show_droplist ");
  942. replyMSG.append(npcId);
  943. replyMSG.append(" ");
  944. replyMSG.append(page - 1);
  945. replyMSG.append("\">Prev Page</a></td>");
  946. if (!hasMore)
  947. {
  948. replyMSG.append("<td width=100>Page ");
  949. replyMSG.append(page);
  950. replyMSG.append("</td><td width=70></td></tr>");
  951. }
  952. }
  953. if (hasMore)
  954. {
  955. if (page <= 1)
  956. replyMSG.append("<td width=120></td>");
  957. replyMSG.append("<td width=100>Page ");
  958. replyMSG.append(page);
  959. replyMSG.append("</td><td width=70><a action=\"bypass -h admin_show_droplist ");
  960. replyMSG.append(npcId);
  961. replyMSG.append(" ");
  962. replyMSG.append(page + 1);
  963. replyMSG.append("\">Next Page</a></td></tr>");
  964. }
  965. replyMSG.append("</table><center><br><button value=\"Add Drop Data\" action=\"bypass -h admin_add_drop ");
  966. replyMSG.append(npcId);
  967. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  968. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  969. adminReply.setHtml(replyMSG.toString());
  970. activeChar.sendPacket(adminReply);
  971. }
  972. private void showEditDropData(L2PcInstance activeChar, int npcId, int itemId, int category)
  973. {
  974. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  975. if (npcData == null)
  976. {
  977. activeChar.sendMessage("Unknown npc template id " + npcId);
  978. return;
  979. }
  980. L2Item itemData = ItemTable.getInstance().getTemplate(itemId);
  981. if (itemData == null)
  982. {
  983. activeChar.sendMessage("Unknown item template id " + itemId);
  984. return;
  985. }
  986. final StringBuilder replyMSG = new StringBuilder();
  987. replyMSG.append("<html><title>Edit drop data</title><body>");
  988. List<L2DropData> dropDatas = null;
  989. if (npcData.getDropData() != null)
  990. {
  991. for (L2DropCategory dropCat : npcData.getDropData())
  992. {
  993. if (dropCat.getCategoryType() == category)
  994. {
  995. dropDatas = dropCat.getAllDrops();
  996. break;
  997. }
  998. }
  999. }
  1000. L2DropData dropData = null;
  1001. if (dropDatas != null)
  1002. {
  1003. for (L2DropData drop : dropDatas)
  1004. {
  1005. if (drop.getItemId() == itemId)
  1006. {
  1007. dropData = drop;
  1008. break;
  1009. }
  1010. }
  1011. }
  1012. if (dropData != null)
  1013. {
  1014. replyMSG.append("<table width=\"100%\"><tr><td>Npc</td><td>");
  1015. replyMSG.append(npcData.name);
  1016. replyMSG.append(" (");
  1017. replyMSG.append(npcId);
  1018. replyMSG.append(")</td></tr><tr><td>Item</td><td>");
  1019. replyMSG.append(itemData.getName());
  1020. replyMSG.append(" (");
  1021. replyMSG.append(itemId);
  1022. replyMSG.append(")</td></tr><tr><td>Category</td><td>");
  1023. replyMSG.append(((category == -1) ? "-1 (sweep)" : Integer.toString(category)));
  1024. replyMSG.append("</td></tr>");
  1025. replyMSG.append("<tr><td>Min count (");
  1026. replyMSG.append(dropData.getMinDrop());
  1027. replyMSG.append(")</td><td><edit var=\"min\" width=80></td></tr><tr><td>Max count (");
  1028. replyMSG.append(dropData.getMaxDrop());
  1029. replyMSG.append(")</td><td><edit var=\"max\" width=80></td></tr><tr><td>Chance (");
  1030. replyMSG.append(dropData.getChance());
  1031. replyMSG.append(")</td><td><edit var=\"chance\" width=80></td></tr></table><br>");
  1032. replyMSG.append("<center><br><button value=\"Save\" action=\"bypass -h admin_edit_drop ");
  1033. replyMSG.append(npcId);
  1034. replyMSG.append(" ");
  1035. replyMSG.append(itemId);
  1036. replyMSG.append(" ");
  1037. replyMSG.append(category);
  1038. replyMSG.append(" $min $max $chance\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  1039. }
  1040. else
  1041. {
  1042. replyMSG.append("No drop data detail found.<center><br>");
  1043. }
  1044. replyMSG.append("<button value=\"Back to Droplist\" action=\"bypass -h admin_show_droplist ");
  1045. replyMSG.append(npcId);
  1046. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center>");
  1047. replyMSG.append("</body></html>");
  1048. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1049. adminReply.setHtml(replyMSG.toString());
  1050. activeChar.sendPacket(adminReply);
  1051. }
  1052. private void showAddDropData(L2PcInstance activeChar, L2NpcTemplate npcData)
  1053. {
  1054. final String replyMSG = StringUtil.concat("<html><title>Add drop data</title><body><table width=\"100%\"><tr><td>Npc</td><td>",
  1055. npcData.name,
  1056. " (",
  1057. Integer.toString(npcData.npcId),
  1058. ")",
  1059. "</td></tr><tr><td>Item Id</td><td><edit var=\"itemId\" width=80></td></tr><tr><td>Min count</td><td><edit var=\"min\" width=80></td></tr><tr><td>Max count</td><td><edit var=\"max\" width=80></td></tr><tr><td>Category (sweep=-1)</td><td><edit var=\"category\" width=80></td></tr><tr><td>Chance (0-1000000)</td><td><edit var=\"chance\" width=80></td></tr></table><center><br><button value=\"Add\" action=\"bypass -h admin_add_drop ",
  1060. Integer.toString(npcData.npcId),
  1061. " $itemId $category $min $max $chance\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Back to Droplist\" action=\"bypass -h admin_show_droplist ",
  1062. Integer.toString(npcData.npcId),
  1063. "\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1064. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1065. adminReply.setHtml(replyMSG);
  1066. activeChar.sendPacket(adminReply);
  1067. }
  1068. private void updateDropData(L2PcInstance activeChar, int npcId, int itemId, int min, int max, int category, int chance)
  1069. {
  1070. Connection con = null;
  1071. try
  1072. {
  1073. con = L2DatabaseFactory.getInstance().getConnection();
  1074. int updated = 0;
  1075. if (Config.CUSTOM_DROPLIST_TABLE)
  1076. {
  1077. PreparedStatement statement = con.prepareStatement("UPDATE `custom_droplist` SET `min`=?, `max`=?, `chance`=? WHERE `mobId`=? AND `itemId`=? AND `category`=?");
  1078. statement.setInt(1, min);
  1079. statement.setInt(2, max);
  1080. statement.setInt(3, chance);
  1081. statement.setInt(4, npcId);
  1082. statement.setInt(5, itemId);
  1083. statement.setInt(6, category);
  1084. updated = statement.executeUpdate();
  1085. statement.close();
  1086. }
  1087. if (updated == 0)
  1088. {
  1089. PreparedStatement statement = con.prepareStatement("UPDATE `droplist` SET `min`=?, `max`=?, `chance`=? WHERE `mobId`=? AND `itemId`=? AND `category`=?");
  1090. statement.setInt(1, min);
  1091. statement.setInt(2, max);
  1092. statement.setInt(3, chance);
  1093. statement.setInt(4, npcId);
  1094. statement.setInt(5, itemId);
  1095. statement.setInt(6, category);
  1096. updated = statement.executeUpdate();
  1097. statement.close();
  1098. }
  1099. reloadNpcDropList(npcId);
  1100. showNpcDropList(activeChar, npcId, 1);
  1101. activeChar.sendMessage("Updated drop data for npc id " + npcId + " and item id " + itemId + " in category " + category + ".");
  1102. }
  1103. catch (Exception e)
  1104. {
  1105. activeChar.sendMessage("Could not update drop data!");
  1106. _log.warning("Error while updating drop data (" + npcId + ", " + itemId + ", " + min + ", " + max + ", " + category + ", " + chance + "): " + e);
  1107. }
  1108. finally
  1109. {
  1110. L2DatabaseFactory.close(con);
  1111. }
  1112. }
  1113. private void addDropData(L2PcInstance activeChar, int npcId, int itemId, int min, int max, int category, int chance)
  1114. {
  1115. Connection con = null;
  1116. try
  1117. {
  1118. con = L2DatabaseFactory.getInstance().getConnection();
  1119. String table = "droplist";
  1120. if (Config.CUSTOM_DROPLIST_TABLE)
  1121. table = "custom_droplist";
  1122. PreparedStatement statement = con.prepareStatement("INSERT INTO `" + table + "`(`mobId`, `itemId`, `min`, `max`, `category`, `chance`) VALUES(?,?,?,?,?,?)");
  1123. statement.setInt(1, npcId);
  1124. statement.setInt(2, itemId);
  1125. statement.setInt(3, min);
  1126. statement.setInt(4, max);
  1127. statement.setInt(5, category);
  1128. statement.setInt(6, chance);
  1129. statement.execute();
  1130. statement.close();
  1131. reloadNpcDropList(npcId);
  1132. showNpcDropList(activeChar, npcId, 1);
  1133. activeChar.sendMessage("Added drop data for npc id " + npcId + " with item id " + itemId + " in category " + category + ".");
  1134. }
  1135. catch (Exception e)
  1136. {
  1137. activeChar.sendMessage("Could not add drop data!");
  1138. _log.warning("Error while adding drop data (" + npcId + ", " + itemId + ", " + min + ", " + max + ", " + category + ", " + chance + "): " + e);
  1139. }
  1140. finally
  1141. {
  1142. L2DatabaseFactory.close(con);
  1143. }
  1144. }
  1145. private void deleteDropData(L2PcInstance activeChar, int npcId, int itemId, int category, boolean confirmed)
  1146. {
  1147. if (!confirmed)
  1148. {
  1149. final String replyMSG = StringUtil.concat("<html><title>Drop Data Delete</title><body><br>Delete drop data.",
  1150. "<table width=\"100%\"><tr><td>NPC</td><td>",
  1151. NpcTable.getInstance().getTemplate(npcId).name,
  1152. " (",
  1153. Integer.toString(npcId),
  1154. ")</td></tr><tr><td>Item ID</td><td>",
  1155. Integer.toString(itemId),
  1156. "</td></tr><tr><td>Category</td><td>",
  1157. Integer.toString(category),
  1158. "</td></tr></table><center><br><button value=\"Delete\" action=\"bypass -h admin_del_drop ",
  1159. Integer.toString(npcId),
  1160. " ",
  1161. Integer.toString(itemId),
  1162. " ",
  1163. Integer.toString(category),
  1164. " 1\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Back to Droplist\" action=\"bypass -h admin_show_droplist ",
  1165. Integer.toString(npcId),
  1166. "\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1167. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1168. adminReply.setHtml(replyMSG);
  1169. activeChar.sendPacket(adminReply);
  1170. return;
  1171. }
  1172. Connection con = null;
  1173. try
  1174. {
  1175. con = L2DatabaseFactory.getInstance().getConnection();
  1176. int updated = 0;
  1177. if (Config.CUSTOM_DROPLIST_TABLE)
  1178. {
  1179. PreparedStatement statement = con.prepareStatement("DELETE FROM `custom_droplist` WHERE `mobId`=? AND `itemId`=? AND `category`=?");
  1180. statement.setInt(1, npcId);
  1181. statement.setInt(2, itemId);
  1182. statement.setInt(3, category);
  1183. updated = statement.executeUpdate();
  1184. statement.close();
  1185. }
  1186. if (updated == 0)
  1187. {
  1188. PreparedStatement statement = con.prepareStatement("DELETE FROM `droplist` WHERE `mobId`=? AND `itemId`=? AND `category`=?");
  1189. statement.setInt(1, npcId);
  1190. statement.setInt(2, itemId);
  1191. statement.setInt(3, category);
  1192. updated = statement.executeUpdate();
  1193. statement.close();
  1194. }
  1195. reloadNpcDropList(npcId);
  1196. showNpcDropList(activeChar, npcId, 1);
  1197. activeChar.sendMessage("Deleted drop data for npc id " + npcId + " and item id " + itemId + " in category " + category + ".");
  1198. }
  1199. catch (Exception e)
  1200. {
  1201. activeChar.sendMessage("Could not delete drop data!");
  1202. _log.warning("Error while deleting drop data (" + npcId + ", " + itemId + ", " + category + "): " + e);
  1203. }
  1204. finally
  1205. {
  1206. L2DatabaseFactory.close(con);
  1207. }
  1208. }
  1209. private void reloadNpcDropList(int npcId)
  1210. {
  1211. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1212. if (npcData == null)
  1213. return;
  1214. // reset the drop lists
  1215. npcData.clearAllDropData();
  1216. // get the drops
  1217. Connection con = null;
  1218. try
  1219. {
  1220. con = L2DatabaseFactory.getInstance().getConnection();
  1221. L2DropData dropData = null;
  1222. PreparedStatement statement = con.prepareStatement("SELECT `mobId`, `itemId`, `min`, `max`, `category`, `chance` FROM `droplist` WHERE `mobId`=?");
  1223. statement.setInt(1, npcId);
  1224. ResultSet dropDataList = statement.executeQuery();
  1225. while (dropDataList.next())
  1226. {
  1227. dropData = new L2DropData();
  1228. dropData.setItemId(dropDataList.getInt("itemId"));
  1229. dropData.setMinDrop(dropDataList.getInt("min"));
  1230. dropData.setMaxDrop(dropDataList.getInt("max"));
  1231. dropData.setChance(dropDataList.getInt("chance"));
  1232. int category = dropDataList.getInt("category");
  1233. npcData.addDropData(dropData, category);
  1234. }
  1235. dropDataList.close();
  1236. statement.close();
  1237. if (Config.CUSTOM_DROPLIST_TABLE)
  1238. {
  1239. PreparedStatement statement2 = con.prepareStatement("SELECT `mobId`, `itemId`, `min`, `max`, `category`, `chance` FROM `custom_droplist` WHERE `mobId`=?");
  1240. statement2.setInt(1, npcId);
  1241. ResultSet dropDataList2 = statement2.executeQuery();
  1242. while (dropDataList2.next())
  1243. {
  1244. dropData = new L2DropData();
  1245. dropData.setItemId(dropDataList2.getInt("itemId"));
  1246. dropData.setMinDrop(dropDataList2.getInt("min"));
  1247. dropData.setMaxDrop(dropDataList2.getInt("max"));
  1248. dropData.setChance(dropDataList2.getInt("chance"));
  1249. int category = dropDataList2.getInt("category");
  1250. npcData.addDropData(dropData, category);
  1251. }
  1252. dropDataList2.close();
  1253. statement2.close();
  1254. }
  1255. }
  1256. catch (Exception e)
  1257. {
  1258. _log.warning("Error while reloading npc droplist (" + npcId + "): " + e);
  1259. }
  1260. finally
  1261. {
  1262. L2DatabaseFactory.close(con);
  1263. }
  1264. }
  1265. private void showNpcSkillList(L2PcInstance activeChar, int npcId, int page)
  1266. {
  1267. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1268. if (npcData == null)
  1269. {
  1270. activeChar.sendMessage("Template id unknown: " + npcId);
  1271. return;
  1272. }
  1273. Map<Integer, L2Skill> skills = new FastMap<Integer, L2Skill>();
  1274. if (npcData.getSkills() != null)
  1275. skills = npcData.getSkills();
  1276. int _skillsize = skills.size();
  1277. int MaxSkillsPerPage = PAGE_LIMIT;
  1278. int MaxPages = _skillsize / MaxSkillsPerPage;
  1279. if (_skillsize > MaxSkillsPerPage * MaxPages)
  1280. MaxPages++;
  1281. if (page > MaxPages)
  1282. page = MaxPages;
  1283. int SkillsStart = MaxSkillsPerPage * page;
  1284. int SkillsEnd = _skillsize;
  1285. if (SkillsEnd - SkillsStart > MaxSkillsPerPage)
  1286. SkillsEnd = SkillsStart + MaxSkillsPerPage;
  1287. StringBuffer replyMSG = new StringBuffer("<html><title>Show NPC Skill List</title><body><center><font color=\"LEVEL\">");
  1288. replyMSG.append(npcData.getName());
  1289. replyMSG.append(" (");
  1290. replyMSG.append(npcData.npcId);
  1291. replyMSG.append("): ");
  1292. replyMSG.append(_skillsize);
  1293. replyMSG.append(" skills</font></center><table width=300 bgcolor=666666><tr>");
  1294. for (int x = 0; x < MaxPages; x++)
  1295. {
  1296. int pagenr = x + 1;
  1297. if (page == x)
  1298. {
  1299. replyMSG.append("<td>Page ");
  1300. replyMSG.append(pagenr);
  1301. replyMSG.append("</td>");
  1302. }
  1303. else
  1304. {
  1305. replyMSG.append("<td><a action=\"bypass -h admin_show_skilllist_npc ");
  1306. replyMSG.append(npcData.npcId);
  1307. replyMSG.append(" ");
  1308. replyMSG.append(x);
  1309. replyMSG.append("\"> Page ");
  1310. replyMSG.append(pagenr);
  1311. replyMSG.append(" </a></td>");
  1312. }
  1313. }
  1314. replyMSG.append("</tr></table><table width=\"100%\" border=0><tr><td>Skill name [skill id-skill lvl]</td><td>Delete</td></tr>");
  1315. Set<Integer> skillset = skills.keySet();
  1316. Iterator<Integer> skillite = skillset.iterator();
  1317. int skillobj = 0;
  1318. for (int i = 0; i < SkillsStart; i++)
  1319. {
  1320. if (skillite.hasNext())
  1321. skillite.next();
  1322. }
  1323. int cnt = SkillsStart;
  1324. while (skillite.hasNext())
  1325. {
  1326. cnt++;
  1327. if (cnt > SkillsEnd)
  1328. break;
  1329. skillobj = skillite.next();
  1330. replyMSG.append("<tr><td width=240><a action=\"bypass -h admin_edit_skill_npc ");
  1331. replyMSG.append(npcData.npcId);
  1332. replyMSG.append(" ");
  1333. replyMSG.append(skills.get(skillobj).getId());
  1334. replyMSG.append("\">");
  1335. if (skills.get(skillobj).getSkillType() == L2SkillType.NOTDONE)
  1336. replyMSG.append("<font color=\"777777\">"+skills.get(skillobj).getName()+"</font>");
  1337. else
  1338. replyMSG.append(skills.get(skillobj).getName());
  1339. replyMSG.append(" [");
  1340. replyMSG.append(skills.get(skillobj).getId());
  1341. replyMSG.append("-");
  1342. replyMSG.append(skills.get(skillobj).getLevel());
  1343. replyMSG.append("]</a></td><td width=60><a action=\"bypass -h admin_del_skill_npc ");
  1344. replyMSG.append(npcData.npcId);
  1345. replyMSG.append(" ");
  1346. replyMSG.append(skillobj);
  1347. replyMSG.append("\">Delete</a></td></tr>");
  1348. }
  1349. replyMSG.append("</table><br><center><button value=\"Add Skill\" action=\"bypass -h admin_add_skill_npc ");
  1350. replyMSG.append(npcId);
  1351. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1352. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1353. adminReply.setHtml(replyMSG.toString());
  1354. activeChar.sendPacket(adminReply);
  1355. }
  1356. private void showNpcSkillEdit(L2PcInstance activeChar, int npcId, int skillId)
  1357. {
  1358. try
  1359. {
  1360. StringBuffer replyMSG = new StringBuffer("<html><title>NPC Skill Edit</title><body>");
  1361. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1362. if (npcData == null)
  1363. {
  1364. activeChar.sendMessage("Template id unknown: " + npcId);
  1365. return;
  1366. }
  1367. if (npcData.getSkills() == null)
  1368. return;
  1369. L2Skill npcSkill = npcData.getSkills().get(skillId);
  1370. if (npcSkill != null)
  1371. {
  1372. replyMSG.append("<table width=\"100%\"><tr><td>NPC: </td><td>");
  1373. replyMSG.append(NpcTable.getInstance().getTemplate(npcId).getName());
  1374. replyMSG.append(" (");
  1375. replyMSG.append(npcId);
  1376. replyMSG.append(")</td></tr><tr><td>Skill: </td><td>");
  1377. replyMSG.append(npcSkill.getName());
  1378. replyMSG.append(" (");
  1379. replyMSG.append(skillId);
  1380. replyMSG.append(")</td></tr><tr><td>Skill Lvl: (");
  1381. replyMSG.append(npcSkill.getLevel());
  1382. replyMSG.append(") </td><td><edit var=\"level\" width=50></td></tr></table><br><center><button value=\"Save\" action=\"bypass -h admin_edit_skill_npc ");
  1383. replyMSG.append(npcId);
  1384. replyMSG.append(" ");
  1385. replyMSG.append(skillId);
  1386. replyMSG.append(" $level\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br1><button value=\"Back to SkillList\" action=\"bypass -h admin_show_skilllist_npc ");
  1387. replyMSG.append(npcId);
  1388. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center>");
  1389. }
  1390. replyMSG.append("</body></html>");
  1391. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1392. adminReply.setHtml(replyMSG.toString());
  1393. activeChar.sendPacket(adminReply);
  1394. }
  1395. catch (Exception e)
  1396. {
  1397. activeChar.sendMessage("Could not edit npc skills!");
  1398. _log.warning("Error while editing npc skills (" + npcId + ", " + skillId + "): " + e);
  1399. }
  1400. }
  1401. private void updateNpcSkillData(L2PcInstance activeChar, int npcId, int skillId, int level)
  1402. {
  1403. Connection con = null;
  1404. try
  1405. {
  1406. L2Skill skillData = SkillTable.getInstance().getInfo(skillId, level);
  1407. if (skillData == null)
  1408. {
  1409. activeChar.sendMessage("Could not update npc skill: not existing skill id with that level!");
  1410. showNpcSkillEdit(activeChar, npcId, skillId);
  1411. return;
  1412. }
  1413. if (skillData.getLevel() != level)
  1414. {
  1415. activeChar.sendMessage("Skill id with requested level doesn't exist! Skill level not changed.");
  1416. showNpcSkillEdit(activeChar, npcId, skillId);
  1417. return;
  1418. }
  1419. con = L2DatabaseFactory.getInstance().getConnection();
  1420. int updated = 0;
  1421. if(Config.CUSTOM_NPC_SKILLS_TABLE)
  1422. {
  1423. PreparedStatement statement2 = con.prepareStatement("UPDATE `custom_npcskills` SET `level`=? WHERE `npcid`=? AND `skillid`=?");
  1424. statement2.setInt(1, level);
  1425. statement2.setInt(2, npcId);
  1426. statement2.setInt(3, skillId);
  1427. updated = statement2.executeUpdate();
  1428. statement2.close();
  1429. }
  1430. if(updated == 0)
  1431. {
  1432. PreparedStatement statement = con.prepareStatement("UPDATE `npcskills` SET `level`=? WHERE `npcid`=? AND `skillid`=?");
  1433. statement.setInt(1, level);
  1434. statement.setInt(2, npcId);
  1435. statement.setInt(3, skillId);
  1436. statement.execute();
  1437. statement.close();
  1438. }
  1439. reloadNpcSkillList(npcId);
  1440. showNpcSkillList(activeChar, npcId, 0);
  1441. activeChar.sendMessage("Updated skill id " + skillId + " for npc id " + npcId + " to level " + level + ".");
  1442. }
  1443. catch (Exception e)
  1444. {
  1445. activeChar.sendMessage("Could not update npc skill!");
  1446. _log.warning("Error while updating npc skill (" + npcId + ", " + skillId + ", " + level + "): " + e);
  1447. }
  1448. finally
  1449. {
  1450. L2DatabaseFactory.close(con);
  1451. }
  1452. }
  1453. private void showNpcSkillAdd(L2PcInstance activeChar, int npcId)
  1454. {
  1455. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1456. StringBuffer replyMSG = new StringBuffer("<html><title>NPC Skill Add</title><body><table width=\"100%\"><tr><td>NPC: </td><td>");
  1457. replyMSG.append(npcData.getName());
  1458. replyMSG.append(" (");
  1459. replyMSG.append(npcData.npcId);
  1460. replyMSG.append(")</td></tr><tr><td>SkillId: </td><td><edit var=\"skillId\" width=80></td></tr><tr><td>Level: </td><td><edit var=\"level\" width=80></td></tr></table><br><center><button value=\"Add Skill\" action=\"bypass -h admin_add_skill_npc ");
  1461. replyMSG.append(npcData.npcId);
  1462. replyMSG.append(" $skillId $level\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br1><button value=\"Back to SkillList\" action=\"bypass -h admin_show_skilllist_npc ");
  1463. replyMSG.append(npcData.npcId);
  1464. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1465. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1466. adminReply.setHtml(replyMSG.toString());
  1467. activeChar.sendPacket(adminReply);
  1468. }
  1469. private void addNpcSkillData(L2PcInstance activeChar, int npcId, int skillId, int level)
  1470. {
  1471. Connection con = null;
  1472. try
  1473. {
  1474. // skill check
  1475. L2Skill skillData = SkillTable.getInstance().getInfo(skillId, level);
  1476. if (skillData == null)
  1477. {
  1478. activeChar.sendMessage("Could not add npc skill: not existing skill id with that level!");
  1479. showNpcSkillAdd(activeChar, npcId);
  1480. return;
  1481. }
  1482. con = L2DatabaseFactory.getInstance().getConnection();
  1483. if(Config.CUSTOM_NPC_SKILLS_TABLE)
  1484. {
  1485. PreparedStatement statement = con.prepareStatement("INSERT INTO `custom_npcskills`(`npcid`, `skillid`, `level`) VALUES(?,?,?)");
  1486. statement.setInt(1, npcId);
  1487. statement.setInt(2, skillId);
  1488. statement.setInt(3, level);
  1489. statement.execute();
  1490. statement.close();
  1491. }
  1492. else
  1493. {
  1494. PreparedStatement statement = con.prepareStatement("INSERT INTO `npcskills`(`npcid`, `skillid`, `level`) VALUES(?,?,?)");
  1495. statement.setInt(1, npcId);
  1496. statement.setInt(2, skillId);
  1497. statement.setInt(3, level);
  1498. statement.execute();
  1499. statement.close();
  1500. }
  1501. reloadNpcSkillList(npcId);
  1502. showNpcSkillList(activeChar, npcId, 0);
  1503. activeChar.sendMessage("Added skill " + skillId + "-" + level + " to npc id " + npcId + ".");
  1504. }
  1505. catch (Exception e)
  1506. {
  1507. activeChar.sendMessage("Could not add npc skill!");
  1508. _log.warning("Error while adding a npc skill (" + npcId + ", " + skillId + ", " + level + "): " + e);
  1509. }
  1510. finally
  1511. {
  1512. L2DatabaseFactory.close(con);
  1513. }
  1514. }
  1515. private void deleteNpcSkillData(L2PcInstance activeChar, int npcId, int skillId)
  1516. {
  1517. Connection con = null;
  1518. try
  1519. {
  1520. con = L2DatabaseFactory.getInstance().getConnection();
  1521. if (npcId > 0)
  1522. {
  1523. int updated = 0;
  1524. if(Config.CUSTOM_NPC_SKILLS_TABLE)
  1525. {
  1526. PreparedStatement statement = con.prepareStatement("DELETE FROM `custom_npcskills` WHERE `npcid`=? AND `skillid`=?");
  1527. statement.setInt(1, npcId);
  1528. statement.setInt(2, skillId);
  1529. updated = statement.executeUpdate();
  1530. statement.close();
  1531. }
  1532. if(updated == 0)
  1533. {
  1534. PreparedStatement statement2 = con.prepareStatement("DELETE FROM `npcskills` WHERE `npcid`=? AND `skillid`=?");
  1535. statement2.setInt(1, npcId);
  1536. statement2.setInt(2, skillId);
  1537. statement2.execute();
  1538. statement2.close();
  1539. }
  1540. reloadNpcSkillList(npcId);
  1541. showNpcSkillList(activeChar, npcId, 0);
  1542. activeChar.sendMessage("Deleted skill id " + skillId + " from npc id " + npcId + ".");
  1543. }
  1544. }
  1545. catch (Exception e)
  1546. {
  1547. activeChar.sendMessage("Could not delete npc skill!");
  1548. _log.warning("Error while deleting npc skill (" + npcId + ", " + skillId + "): " + e);
  1549. }
  1550. finally
  1551. {
  1552. L2DatabaseFactory.close(con);
  1553. }
  1554. }
  1555. private void reloadNpcSkillList(int npcId)
  1556. {
  1557. Connection con = null;
  1558. try
  1559. {
  1560. con = L2DatabaseFactory.getInstance().getConnection();
  1561. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1562. L2Skill skillData = null;
  1563. if (npcData.getSkills() != null)
  1564. npcData.getSkills().clear();
  1565. // without race
  1566. PreparedStatement statement = con.prepareStatement("SELECT `skillid`, `level` FROM `npcskills` WHERE `npcid`=? AND `skillid` <> 4416");
  1567. statement.setInt(1, npcId);
  1568. ResultSet skillDataList = statement.executeQuery();
  1569. while (skillDataList.next())
  1570. {
  1571. int idval = skillDataList.getInt("skillid");
  1572. int levelval = skillDataList.getInt("level");
  1573. skillData = SkillTable.getInstance().getInfo(idval, levelval);
  1574. if (skillData != null)
  1575. npcData.addSkill(skillData);
  1576. }
  1577. skillDataList.close();
  1578. statement.close();
  1579. if(Config.CUSTOM_NPC_SKILLS_TABLE)
  1580. {
  1581. PreparedStatement statement2 = con.prepareStatement("SELECT `skillid`, `level` FROM `npcskills` WHERE `npcid`=? AND `skillid` <> 4416");
  1582. statement2.setInt(1, npcId);
  1583. ResultSet skillDataList2 = statement2.executeQuery();
  1584. while (skillDataList2.next())
  1585. {
  1586. int idval = skillDataList2.getInt("skillid");
  1587. int levelval = skillDataList2.getInt("level");
  1588. skillData = SkillTable.getInstance().getInfo(idval, levelval);
  1589. if (skillData != null)
  1590. npcData.addSkill(skillData);
  1591. }
  1592. skillDataList2.close();
  1593. statement2.close();
  1594. }
  1595. }
  1596. catch (Exception e)
  1597. {
  1598. _log.warning("Error while reloading npc skill list (" + npcId + "): " + e);
  1599. }
  1600. finally
  1601. {
  1602. L2DatabaseFactory.close(con);
  1603. }
  1604. }
  1605. }