AdminEditNpc.java 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680
  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.HashMap;
  20. import java.util.Iterator;
  21. import java.util.List;
  22. import java.util.Map;
  23. import java.util.StringTokenizer;
  24. import java.util.logging.Level;
  25. import java.util.logging.Logger;
  26. import com.l2jserver.Config;
  27. import com.l2jserver.L2DatabaseFactory;
  28. import com.l2jserver.gameserver.TradeController;
  29. import com.l2jserver.gameserver.cache.HtmCache;
  30. import com.l2jserver.gameserver.datatables.ItemTable;
  31. import com.l2jserver.gameserver.datatables.MerchantPriceConfigTable.MerchantPriceConfig;
  32. import com.l2jserver.gameserver.datatables.NpcTable;
  33. import com.l2jserver.gameserver.datatables.SkillTable;
  34. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  35. import com.l2jserver.gameserver.model.L2DropCategory;
  36. import com.l2jserver.gameserver.model.L2DropData;
  37. import com.l2jserver.gameserver.model.L2Object;
  38. import com.l2jserver.gameserver.model.L2TradeList;
  39. import com.l2jserver.gameserver.model.L2TradeList.L2TradeItem;
  40. import com.l2jserver.gameserver.model.StatsSet;
  41. import com.l2jserver.gameserver.model.actor.L2Npc;
  42. import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
  43. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  44. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  45. import com.l2jserver.gameserver.model.items.L2Item;
  46. import com.l2jserver.gameserver.model.skills.L2Skill;
  47. import com.l2jserver.gameserver.model.skills.L2SkillType;
  48. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  49. import com.l2jserver.util.StringUtil;
  50. /**
  51. * @author terry
  52. * con.close() change by Zoey76 24/02/2011
  53. */
  54. public class AdminEditNpc implements IAdminCommandHandler
  55. {
  56. private static Logger _log = Logger.getLogger(AdminEditNpc.class.getName());
  57. private final static int PAGE_LIMIT = 20;
  58. private static final String[] ADMIN_COMMANDS =
  59. {
  60. "admin_edit_npc",
  61. "admin_save_npc",
  62. "admin_show_droplist",
  63. "admin_edit_drop",
  64. "admin_add_drop",
  65. "admin_del_drop",
  66. "admin_showShop",
  67. "admin_showShopList",
  68. "admin_addShopItem",
  69. "admin_delShopItem",
  70. "admin_editShopItem",
  71. "admin_close_window",
  72. "admin_show_skilllist_npc",
  73. "admin_add_skill_npc",
  74. "admin_edit_skill_npc",
  75. "admin_del_skill_npc",
  76. "admin_log_npc_spawn"
  77. };
  78. @Override
  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. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  583. {
  584. String table = "merchant_buylists";
  585. if (Config.CUSTOM_MERCHANT_TABLES)
  586. table = "custom_merchant_buylists";
  587. PreparedStatement stmt = con.prepareStatement("INSERT INTO `" + table + "`(`item_id`,`price`,`shop_id`,`order`) VALUES (?,?,?,?)");
  588. stmt.setInt(1, itemID);
  589. stmt.setLong(2, price);
  590. stmt.setInt(3, tradeListID);
  591. stmt.setInt(4, order);
  592. stmt.execute();
  593. stmt.close();
  594. }
  595. catch (Exception e)
  596. {
  597. _log.warning("Could not store trade list (" + itemID + ", " + price + ", " + tradeListID + ", " + order + "): " + e);
  598. return false;
  599. }
  600. return true;
  601. }
  602. private void updateTradeList(int itemID, long price, int tradeListID, int order)
  603. {
  604. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  605. {
  606. int updated = 0;
  607. if (Config.CUSTOM_MERCHANT_TABLES)
  608. {
  609. PreparedStatement stmt = con.prepareStatement("UPDATE `custom_merchant_buylists` SET `price` = ? WHERE `shop_id` = ? AND `order` = ?");
  610. stmt.setLong(1, price);
  611. stmt.setInt(2, tradeListID);
  612. stmt.setInt(3, order);
  613. updated = stmt.executeUpdate();
  614. stmt.close();
  615. }
  616. if (updated == 0)
  617. {
  618. PreparedStatement stmt = con.prepareStatement("UPDATE `merchant_buylists` SET `price` = ? WHERE `shop_id` = ? AND `order` = ?");
  619. stmt.setLong(1, price);
  620. stmt.setInt(2, tradeListID);
  621. stmt.setInt(3, order);
  622. updated = stmt.executeUpdate();
  623. stmt.close();
  624. }
  625. }
  626. catch (Exception e)
  627. {
  628. _log.warning("Could not update trade list (" + itemID + ", " + price + ", " + tradeListID + ", " + order + "): " + e);
  629. }
  630. }
  631. private void deleteTradeList(int tradeListID, int order)
  632. {
  633. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  634. {
  635. int updated = 0;
  636. if (Config.CUSTOM_MERCHANT_TABLES)
  637. {
  638. PreparedStatement stmt = con.prepareStatement("DELETE FROM `custom_merchant_buylists` WHERE `shop_id` = ? AND `order` = ?");
  639. stmt.setInt(1, tradeListID);
  640. stmt.setInt(2, order);
  641. updated = stmt.executeUpdate();
  642. stmt.close();
  643. }
  644. if (updated == 0)
  645. {
  646. PreparedStatement stmt = con.prepareStatement("DELETE FROM `merchant_buylists` WHERE `shop_id` = ? AND `order` = ?");
  647. stmt.setInt(1, tradeListID);
  648. stmt.setInt(2, order);
  649. updated = stmt.executeUpdate();
  650. stmt.close();
  651. }
  652. }
  653. catch (Exception e)
  654. {
  655. _log.warning("Could not delete trade list (" + tradeListID + ", " + order + "): " + e);
  656. }
  657. }
  658. private int findOrderTradeList(int itemID, long price, int tradeListID)
  659. {
  660. int order = -1;
  661. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  662. {
  663. PreparedStatement stmt = con.prepareStatement("SELECT `order` FROM `merchant_buylists` WHERE `shop_id` = ? AND `item_id` = ? AND `price` = ?");
  664. stmt.setInt(1, tradeListID);
  665. stmt.setInt(2, itemID);
  666. stmt.setLong(3, price);
  667. ResultSet rs = stmt.executeQuery();
  668. if (rs.first())
  669. order = rs.getInt("order");
  670. stmt.close();
  671. rs.close();
  672. }
  673. catch (Exception e)
  674. {
  675. _log.warning("Could not get order for (" + itemID + ", " + price + ", " + tradeListID + "): " + e);
  676. }
  677. return order;
  678. }
  679. @Override
  680. public String[] getAdminCommandList()
  681. {
  682. return ADMIN_COMMANDS;
  683. }
  684. private void showNpcProperty(L2PcInstance activeChar, L2NpcTemplate npc)
  685. {
  686. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  687. String content = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/editnpc.htm");
  688. if (content != null)
  689. {
  690. adminReply.setHtml(content);
  691. adminReply.replace("%npcId%", String.valueOf(npc.getNpcId()));
  692. adminReply.replace("%templateId%", String.valueOf(npc.getIdTemplate()));
  693. adminReply.replace("%name%", npc.getName());
  694. adminReply.replace("%serverSideName%", npc.isServerSideName() == true ? "1" : "0");
  695. adminReply.replace("%title%", npc.getTitle());
  696. adminReply.replace("%serverSideTitle%", npc.isServerSideTitle() == true ? "1" : "0");
  697. adminReply.replace("%collisionRadius%", String.valueOf(npc.getfCollisionRadius()));
  698. adminReply.replace("%collisionHeight%", String.valueOf(npc.getfCollisionHeight()));
  699. adminReply.replace("%level%", String.valueOf(npc.getLevel()));
  700. adminReply.replace("%sex%", String.valueOf(npc.getSex()));
  701. adminReply.replace("%type%", String.valueOf(npc.getType()));
  702. adminReply.replace("%attackRange%", String.valueOf(npc.getBaseAtkRange()));
  703. adminReply.replace("%hp%", String.valueOf(npc.getBaseHpMax()));
  704. adminReply.replace("%mp%", String.valueOf(npc.getBaseMpMax()));
  705. adminReply.replace("%hpRegen%", String.valueOf(npc.getBaseHpReg()));
  706. adminReply.replace("%mpRegen%", String.valueOf(npc.getBaseMpReg()));
  707. adminReply.replace("%str%", String.valueOf(npc.getBaseSTR()));
  708. adminReply.replace("%con%", String.valueOf(npc.getBaseCON()));
  709. adminReply.replace("%dex%", String.valueOf(npc.getBaseDEX()));
  710. adminReply.replace("%int%", String.valueOf(npc.getBaseINT()));
  711. adminReply.replace("%wit%", String.valueOf(npc.getBaseWIT()));
  712. adminReply.replace("%men%", String.valueOf(npc.getBaseMEN()));
  713. adminReply.replace("%exp%", String.valueOf(npc.getRewardExp()));
  714. adminReply.replace("%sp%", String.valueOf(npc.getRewardSp()));
  715. adminReply.replace("%pAtk%", String.valueOf(npc.getBasePAtk()));
  716. adminReply.replace("%pDef%", String.valueOf(npc.getBasePDef()));
  717. adminReply.replace("%mAtk%", String.valueOf(npc.getBaseMAtk()));
  718. adminReply.replace("%mDef%", String.valueOf(npc.getBaseMDef()));
  719. adminReply.replace("%pAtkSpd%", String.valueOf(npc.getBasePAtkSpd()));
  720. adminReply.replace("%aggro%", String.valueOf(npc.getAIDataStatic().getAggroRange()));
  721. adminReply.replace("%mAtkSpd%", String.valueOf(npc.getBaseMAtkSpd()));
  722. adminReply.replace("%rHand%", String.valueOf(npc.getRightHand()));
  723. adminReply.replace("%lHand%", String.valueOf(npc.getLeftHand()));
  724. adminReply.replace("%enchant%", String.valueOf(npc.getEnchantEffect()));
  725. adminReply.replace("%walkSpd%", String.valueOf(npc.getBaseWalkSpd()));
  726. adminReply.replace("%runSpd%", String.valueOf(npc.getBaseRunSpd()));
  727. adminReply.replace("%factionId%", npc.getAIDataStatic().getClan() == null ? "" : npc.getAIDataStatic().getClan());
  728. adminReply.replace("%factionRange%", String.valueOf(npc.getAIDataStatic().getClanRange()));
  729. }
  730. else
  731. adminReply.setHtml("<html><head><body>File not found: data/html/admin/editnpc.htm</body></html>");
  732. activeChar.sendPacket(adminReply);
  733. }
  734. private void saveNpcProperty(L2PcInstance activeChar, String command)
  735. {
  736. String[] commandSplit = command.split(" ");
  737. if (commandSplit.length < 4)
  738. return;
  739. StatsSet newNpcData = new StatsSet();
  740. try
  741. {
  742. newNpcData.set("npcId", commandSplit[1]);
  743. String statToSet = commandSplit[2];
  744. String value = commandSplit[3];
  745. if (commandSplit.length > 4)
  746. {
  747. for (int i = 0; i < commandSplit.length - 3; i++)
  748. value += " " + commandSplit[i + 4];
  749. }
  750. if (statToSet.equals("templateId"))
  751. newNpcData.set("idTemplate", Integer.parseInt(value));
  752. else if (statToSet.equals("name"))
  753. newNpcData.set("name", value);
  754. else if (statToSet.equals("serverSideName"))
  755. newNpcData.set("serverSideName", Integer.parseInt(value));
  756. else if (statToSet.equals("title"))
  757. newNpcData.set("title", value);
  758. else if (statToSet.equals("serverSideTitle"))
  759. newNpcData.set("serverSideTitle", Integer.parseInt(value) == 1 ? 1 : 0);
  760. else if (statToSet.equals("collisionRadius"))
  761. newNpcData.set("collision_radius", Integer.parseInt(value));
  762. else if (statToSet.equals("collisionHeight"))
  763. newNpcData.set("collision_height", Integer.parseInt(value));
  764. else if (statToSet.equals("level"))
  765. newNpcData.set("level", Integer.parseInt(value));
  766. else if (statToSet.equals("sex"))
  767. {
  768. int intValue = Integer.parseInt(value);
  769. newNpcData.set("sex", intValue == 0 ? "male" : intValue == 1 ? "female" : "etc");
  770. }
  771. else if (statToSet.equals("type"))
  772. {
  773. Class.forName("com.l2jserver.gameserver.model.actor.instance." + value + "Instance");
  774. newNpcData.set("type", value);
  775. }
  776. else if (statToSet.equals("attackRange"))
  777. newNpcData.set("attackrange", Integer.parseInt(value));
  778. else if (statToSet.equals("hp"))
  779. newNpcData.set("hp", Integer.parseInt(value));
  780. else if (statToSet.equals("mp"))
  781. newNpcData.set("mp", Integer.parseInt(value));
  782. else if (statToSet.equals("hpRegen"))
  783. newNpcData.set("hpreg", Integer.parseInt(value));
  784. else if (statToSet.equals("mpRegen"))
  785. newNpcData.set("mpreg", Integer.parseInt(value));
  786. else if (statToSet.equals("str"))
  787. newNpcData.set("str", Integer.parseInt(value));
  788. else if (statToSet.equals("con"))
  789. newNpcData.set("con", Integer.parseInt(value));
  790. else if (statToSet.equals("dex"))
  791. newNpcData.set("dex", Integer.parseInt(value));
  792. else if (statToSet.equals("int"))
  793. newNpcData.set("int", Integer.parseInt(value));
  794. else if (statToSet.equals("wit"))
  795. newNpcData.set("wit", Integer.parseInt(value));
  796. else if (statToSet.equals("men"))
  797. newNpcData.set("men", Integer.parseInt(value));
  798. else if (statToSet.equals("exp"))
  799. newNpcData.set("exp", Integer.parseInt(value));
  800. else if (statToSet.equals("sp"))
  801. newNpcData.set("sp", Integer.parseInt(value));
  802. else if (statToSet.equals("pAtk"))
  803. newNpcData.set("patk", Integer.parseInt(value));
  804. else if (statToSet.equals("pDef"))
  805. newNpcData.set("pdef", Integer.parseInt(value));
  806. else if (statToSet.equals("mAtk"))
  807. newNpcData.set("matk", Integer.parseInt(value));
  808. else if (statToSet.equals("mDef"))
  809. newNpcData.set("mdef", Integer.parseInt(value));
  810. else if (statToSet.equals("pAtkSpd"))
  811. newNpcData.set("atkspd", Integer.parseInt(value));
  812. else if (statToSet.equals("aggro"))
  813. newNpcData.set("aggro", Integer.parseInt(value));
  814. else if (statToSet.equals("mAtkSpd"))
  815. newNpcData.set("matkspd", Integer.parseInt(value));
  816. else if (statToSet.equals("rHand"))
  817. newNpcData.set("rhand", Integer.parseInt(value));
  818. else if (statToSet.equals("lHand"))
  819. newNpcData.set("lhand", Integer.parseInt(value));
  820. else if (statToSet.equals("armor"))
  821. newNpcData.set("armor", Integer.parseInt(value));
  822. else if (statToSet.equals("enchant"))
  823. newNpcData.set("enchant", Integer.parseInt(value));
  824. else if (statToSet.equals("runSpd"))
  825. newNpcData.set("runspd", Integer.parseInt(value));
  826. else if (statToSet.equals("isUndead"))
  827. newNpcData.set("isUndead", Integer.parseInt(value) == 1 ? 1 : 0);
  828. else if (statToSet.equals("absorbLevel"))
  829. {
  830. int intVal = Integer.parseInt(value);
  831. newNpcData.set("absorb_level", intVal < 0 ? 0 : intVal > 16 ? 0 : intVal);
  832. }
  833. }
  834. catch (Exception e)
  835. {
  836. activeChar.sendMessage("Could not save npc property!");
  837. _log.warning("Error saving new npc value (" + command + "): " + e);
  838. }
  839. NpcTable.getInstance().saveNpc(newNpcData);
  840. int npcId = newNpcData.getInteger("npcId");
  841. NpcTable.getInstance().reloadNpc(npcId);
  842. showNpcProperty(activeChar, NpcTable.getInstance().getTemplate(npcId));
  843. }
  844. private void showNpcDropList(L2PcInstance activeChar, int npcId, int page)
  845. {
  846. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  847. if (npcData == null)
  848. {
  849. activeChar.sendMessage("Unknown npc template id " + npcId);
  850. return;
  851. }
  852. final StringBuilder replyMSG = new StringBuilder(2900);
  853. replyMSG.append("<html><title>Show droplist page ");
  854. replyMSG.append(page);
  855. replyMSG.append("</title><body><br1><center><font color=\"LEVEL\">");
  856. replyMSG.append(npcData.getName());
  857. replyMSG.append(" (");
  858. replyMSG.append(npcId);
  859. 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>");
  860. int myPage = 1;
  861. int i = 0;
  862. int shown = 0;
  863. boolean hasMore = false;
  864. if (npcData.getDropData() != null)
  865. {
  866. for (L2DropCategory cat : npcData.getDropData())
  867. {
  868. if (shown == PAGE_LIMIT)
  869. {
  870. hasMore = true;
  871. break;
  872. }
  873. for (L2DropData drop : cat.getAllDrops())
  874. {
  875. if (myPage != page)
  876. {
  877. i++;
  878. if (i == PAGE_LIMIT)
  879. {
  880. myPage++;
  881. i = 0;
  882. }
  883. continue;
  884. }
  885. if (shown == PAGE_LIMIT)
  886. {
  887. hasMore = true;
  888. break;
  889. }
  890. replyMSG.append("<tr><td>");
  891. replyMSG.append(cat.getCategoryType());
  892. replyMSG.append("</td><td><a action=\"bypass -h admin_edit_drop ");
  893. replyMSG.append(npcId);
  894. replyMSG.append(" ");
  895. replyMSG.append(drop.getItemId());
  896. replyMSG.append(" ");
  897. replyMSG.append(cat.getCategoryType());
  898. replyMSG.append("\">");
  899. replyMSG.append(ItemTable.getInstance().getTemplate(drop.getItemId()).getName());
  900. replyMSG.append(" (");
  901. replyMSG.append(drop.getItemId());
  902. replyMSG.append(")</a></td><td>");
  903. replyMSG.append((drop.isQuestDrop() ? "Q" : (cat.isSweep() ? "S" : "D")));
  904. replyMSG.append("</td><td><a action=\"bypass -h admin_del_drop ");
  905. replyMSG.append(npcId);
  906. replyMSG.append(" ");
  907. replyMSG.append(drop.getItemId());
  908. replyMSG.append(" ");
  909. replyMSG.append(cat.getCategoryType());
  910. replyMSG.append("\">del</a></td></tr>");
  911. shown++;
  912. }
  913. }
  914. }
  915. replyMSG.append("</table><table width=300 bgcolor=666666 border=0><tr>");
  916. if (page > 1)
  917. {
  918. replyMSG.append("<td width=120><a action=\"bypass -h admin_show_droplist ");
  919. replyMSG.append(npcId);
  920. replyMSG.append(" ");
  921. replyMSG.append(page - 1);
  922. replyMSG.append("\">Prev Page</a></td>");
  923. if (!hasMore)
  924. {
  925. replyMSG.append("<td width=100>Page ");
  926. replyMSG.append(page);
  927. replyMSG.append("</td><td width=70></td></tr>");
  928. }
  929. }
  930. if (hasMore)
  931. {
  932. if (page <= 1)
  933. replyMSG.append("<td width=120></td>");
  934. replyMSG.append("<td width=100>Page ");
  935. replyMSG.append(page);
  936. replyMSG.append("</td><td width=70><a action=\"bypass -h admin_show_droplist ");
  937. replyMSG.append(npcId);
  938. replyMSG.append(" ");
  939. replyMSG.append(page + 1);
  940. replyMSG.append("\">Next Page</a></td></tr>");
  941. }
  942. replyMSG.append("</table><center><br><button value=\"Add Drop Data\" action=\"bypass -h admin_add_drop ");
  943. replyMSG.append(npcId);
  944. 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>");
  945. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  946. adminReply.setHtml(replyMSG.toString());
  947. activeChar.sendPacket(adminReply);
  948. }
  949. private void showEditDropData(L2PcInstance activeChar, int npcId, int itemId, int category)
  950. {
  951. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  952. if (npcData == null)
  953. {
  954. activeChar.sendMessage("Unknown npc template id " + npcId);
  955. return;
  956. }
  957. L2Item itemData = ItemTable.getInstance().getTemplate(itemId);
  958. if (itemData == null)
  959. {
  960. activeChar.sendMessage("Unknown item template id " + itemId);
  961. return;
  962. }
  963. final StringBuilder replyMSG = new StringBuilder();
  964. replyMSG.append("<html><title>Edit drop data</title><body>");
  965. List<L2DropData> dropDatas = null;
  966. if (npcData.getDropData() != null)
  967. {
  968. for (L2DropCategory dropCat : npcData.getDropData())
  969. {
  970. if (dropCat.getCategoryType() == category)
  971. {
  972. dropDatas = dropCat.getAllDrops();
  973. break;
  974. }
  975. }
  976. }
  977. L2DropData dropData = null;
  978. if (dropDatas != null)
  979. {
  980. for (L2DropData drop : dropDatas)
  981. {
  982. if (drop.getItemId() == itemId)
  983. {
  984. dropData = drop;
  985. break;
  986. }
  987. }
  988. }
  989. if (dropData != null)
  990. {
  991. replyMSG.append("<table width=\"100%\"><tr><td>Npc</td><td>");
  992. replyMSG.append(npcData.getName());
  993. replyMSG.append(" (");
  994. replyMSG.append(npcId);
  995. replyMSG.append(")</td></tr><tr><td>Item</td><td>");
  996. replyMSG.append(itemData.getName());
  997. replyMSG.append(" (");
  998. replyMSG.append(itemId);
  999. replyMSG.append(")</td></tr><tr><td>Category</td><td>");
  1000. replyMSG.append(((category == -1) ? "-1 (sweep)" : Integer.toString(category)));
  1001. replyMSG.append("</td></tr>");
  1002. replyMSG.append("<tr><td>Min count (");
  1003. replyMSG.append(dropData.getMinDrop());
  1004. replyMSG.append(")</td><td><edit var=\"min\" width=80></td></tr><tr><td>Max count (");
  1005. replyMSG.append(dropData.getMaxDrop());
  1006. replyMSG.append(")</td><td><edit var=\"max\" width=80></td></tr><tr><td>Chance (");
  1007. replyMSG.append(dropData.getChance());
  1008. replyMSG.append(")</td><td><edit var=\"chance\" width=80></td></tr></table><br>");
  1009. replyMSG.append("<center><br><button value=\"Save\" action=\"bypass -h admin_edit_drop ");
  1010. replyMSG.append(npcId);
  1011. replyMSG.append(" ");
  1012. replyMSG.append(itemId);
  1013. replyMSG.append(" ");
  1014. replyMSG.append(category);
  1015. replyMSG.append(" $min $max $chance\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  1016. }
  1017. else
  1018. {
  1019. replyMSG.append("No drop data detail found.<center><br>");
  1020. }
  1021. replyMSG.append("<button value=\"Back to Droplist\" action=\"bypass -h admin_show_droplist ");
  1022. replyMSG.append(npcId);
  1023. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center>");
  1024. replyMSG.append("</body></html>");
  1025. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1026. adminReply.setHtml(replyMSG.toString());
  1027. activeChar.sendPacket(adminReply);
  1028. }
  1029. private void showAddDropData(L2PcInstance activeChar, L2NpcTemplate npcData)
  1030. {
  1031. final String replyMSG = StringUtil.concat("<html><title>Add drop data</title><body><table width=\"100%\"><tr><td>Npc</td><td>",
  1032. npcData.getName(),
  1033. " (",
  1034. Integer.toString(npcData.getNpcId()),
  1035. ")",
  1036. "</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 ",
  1037. Integer.toString(npcData.getNpcId()),
  1038. " $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 ",
  1039. Integer.toString(npcData.getNpcId()),
  1040. "\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1041. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1042. adminReply.setHtml(replyMSG);
  1043. activeChar.sendPacket(adminReply);
  1044. }
  1045. private void updateDropData(L2PcInstance activeChar, int npcId, int itemId, int min, int max, int category, int chance)
  1046. {
  1047. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1048. {
  1049. int updated = 0;
  1050. if (Config.CUSTOM_DROPLIST_TABLE)
  1051. {
  1052. PreparedStatement statement = con.prepareStatement("UPDATE `custom_droplist` SET `min`=?, `max`=?, `chance`=? WHERE `mobId`=? AND `itemId`=? AND `category`=?");
  1053. statement.setInt(1, min);
  1054. statement.setInt(2, max);
  1055. statement.setInt(3, chance);
  1056. statement.setInt(4, npcId);
  1057. statement.setInt(5, itemId);
  1058. statement.setInt(6, category);
  1059. updated = statement.executeUpdate();
  1060. statement.close();
  1061. }
  1062. if (updated == 0)
  1063. {
  1064. PreparedStatement statement = con.prepareStatement("UPDATE `droplist` SET `min`=?, `max`=?, `chance`=? WHERE `mobId`=? AND `itemId`=? AND `category`=?");
  1065. statement.setInt(1, min);
  1066. statement.setInt(2, max);
  1067. statement.setInt(3, chance);
  1068. statement.setInt(4, npcId);
  1069. statement.setInt(5, itemId);
  1070. statement.setInt(6, category);
  1071. updated = statement.executeUpdate();
  1072. statement.close();
  1073. }
  1074. reloadNpcDropList(npcId);
  1075. showNpcDropList(activeChar, npcId, 1);
  1076. activeChar.sendMessage("Updated drop data for npc id " + npcId + " and item id " + itemId + " in category " + category + ".");
  1077. }
  1078. catch (Exception e)
  1079. {
  1080. activeChar.sendMessage("Could not update drop data!");
  1081. _log.warning("Error while updating drop data (" + npcId + ", " + itemId + ", " + min + ", " + max + ", " + category + ", " + chance + "): " + e);
  1082. }
  1083. }
  1084. private void addDropData(L2PcInstance activeChar, int npcId, int itemId, int min, int max, int category, int chance)
  1085. {
  1086. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1087. {
  1088. String table = "droplist";
  1089. if (Config.CUSTOM_DROPLIST_TABLE)
  1090. table = "custom_droplist";
  1091. PreparedStatement statement = con.prepareStatement("INSERT INTO `" + table + "`(`mobId`, `itemId`, `min`, `max`, `category`, `chance`) VALUES(?,?,?,?,?,?)");
  1092. statement.setInt(1, npcId);
  1093. statement.setInt(2, itemId);
  1094. statement.setInt(3, min);
  1095. statement.setInt(4, max);
  1096. statement.setInt(5, category);
  1097. statement.setInt(6, chance);
  1098. statement.execute();
  1099. statement.close();
  1100. reloadNpcDropList(npcId);
  1101. showNpcDropList(activeChar, npcId, 1);
  1102. activeChar.sendMessage("Added drop data for npc id " + npcId + " with item id " + itemId + " in category " + category + ".");
  1103. }
  1104. catch (Exception e)
  1105. {
  1106. activeChar.sendMessage("Could not add drop data!");
  1107. _log.warning("Error while adding drop data (" + npcId + ", " + itemId + ", " + min + ", " + max + ", " + category + ", " + chance + "): " + e);
  1108. }
  1109. }
  1110. private void deleteDropData(L2PcInstance activeChar, int npcId, int itemId, int category, boolean confirmed)
  1111. {
  1112. if (!confirmed)
  1113. {
  1114. final String replyMSG = StringUtil.concat("<html><title>Drop Data Delete</title><body><br>Delete drop data.",
  1115. "<table width=\"100%\"><tr><td>NPC</td><td>",
  1116. NpcTable.getInstance().getTemplate(npcId).getName(),
  1117. " (",
  1118. Integer.toString(npcId),
  1119. ")</td></tr><tr><td>Item ID</td><td>",
  1120. Integer.toString(itemId),
  1121. "</td></tr><tr><td>Category</td><td>",
  1122. Integer.toString(category),
  1123. "</td></tr></table><center><br><button value=\"Delete\" action=\"bypass -h admin_del_drop ",
  1124. Integer.toString(npcId),
  1125. " ",
  1126. Integer.toString(itemId),
  1127. " ",
  1128. Integer.toString(category),
  1129. " 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 ",
  1130. Integer.toString(npcId),
  1131. "\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1132. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1133. adminReply.setHtml(replyMSG);
  1134. activeChar.sendPacket(adminReply);
  1135. return;
  1136. }
  1137. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1138. {
  1139. int updated = 0;
  1140. if (Config.CUSTOM_DROPLIST_TABLE)
  1141. {
  1142. PreparedStatement statement = con.prepareStatement("DELETE FROM `custom_droplist` WHERE `mobId`=? AND `itemId`=? AND `category`=?");
  1143. statement.setInt(1, npcId);
  1144. statement.setInt(2, itemId);
  1145. statement.setInt(3, category);
  1146. updated = statement.executeUpdate();
  1147. statement.close();
  1148. }
  1149. if (updated == 0)
  1150. {
  1151. PreparedStatement statement = con.prepareStatement("DELETE FROM `droplist` WHERE `mobId`=? AND `itemId`=? AND `category`=?");
  1152. statement.setInt(1, npcId);
  1153. statement.setInt(2, itemId);
  1154. statement.setInt(3, category);
  1155. updated = statement.executeUpdate();
  1156. statement.close();
  1157. }
  1158. reloadNpcDropList(npcId);
  1159. showNpcDropList(activeChar, npcId, 1);
  1160. activeChar.sendMessage("Deleted drop data for npc id " + npcId + " and item id " + itemId + " in category " + category + ".");
  1161. }
  1162. catch (Exception e)
  1163. {
  1164. activeChar.sendMessage("Could not delete drop data!");
  1165. _log.warning("Error while deleting drop data (" + npcId + ", " + itemId + ", " + category + "): " + e);
  1166. }
  1167. }
  1168. private void reloadNpcDropList(int npcId)
  1169. {
  1170. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1171. if (npcData == null)
  1172. return;
  1173. // reset the drop lists
  1174. npcData.clearAllDropData();
  1175. // get the drops
  1176. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1177. {
  1178. L2DropData dropData = null;
  1179. PreparedStatement statement = con.prepareStatement("SELECT `mobId`, `itemId`, `min`, `max`, `category`, `chance` FROM `droplist` WHERE `mobId`=?");
  1180. statement.setInt(1, npcId);
  1181. ResultSet dropDataList = statement.executeQuery();
  1182. while (dropDataList.next())
  1183. {
  1184. dropData = new L2DropData();
  1185. dropData.setItemId(dropDataList.getInt("itemId"));
  1186. dropData.setMinDrop(dropDataList.getInt("min"));
  1187. dropData.setMaxDrop(dropDataList.getInt("max"));
  1188. dropData.setChance(dropDataList.getInt("chance"));
  1189. int category = dropDataList.getInt("category");
  1190. npcData.addDropData(dropData, category);
  1191. }
  1192. dropDataList.close();
  1193. statement.close();
  1194. if (Config.CUSTOM_DROPLIST_TABLE)
  1195. {
  1196. PreparedStatement statement2 = con.prepareStatement("SELECT `mobId`, `itemId`, `min`, `max`, `category`, `chance` FROM `custom_droplist` WHERE `mobId`=?");
  1197. statement2.setInt(1, npcId);
  1198. ResultSet dropDataList2 = statement2.executeQuery();
  1199. while (dropDataList2.next())
  1200. {
  1201. dropData = new L2DropData();
  1202. dropData.setItemId(dropDataList2.getInt("itemId"));
  1203. dropData.setMinDrop(dropDataList2.getInt("min"));
  1204. dropData.setMaxDrop(dropDataList2.getInt("max"));
  1205. dropData.setChance(dropDataList2.getInt("chance"));
  1206. int category = dropDataList2.getInt("category");
  1207. npcData.addDropData(dropData, category);
  1208. }
  1209. dropDataList2.close();
  1210. statement2.close();
  1211. }
  1212. }
  1213. catch (Exception e)
  1214. {
  1215. _log.warning("Error while reloading npc droplist (" + npcId + "): " + e);
  1216. }
  1217. }
  1218. private void showNpcSkillList(L2PcInstance activeChar, int npcId, int page)
  1219. {
  1220. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1221. if (npcData == null)
  1222. {
  1223. activeChar.sendMessage("Template id unknown: " + npcId);
  1224. return;
  1225. }
  1226. Map<Integer, L2Skill> skills = new HashMap<>(npcData.getSkills());
  1227. int _skillsize = skills.size();
  1228. int MaxSkillsPerPage = PAGE_LIMIT;
  1229. int MaxPages = _skillsize / MaxSkillsPerPage;
  1230. if (_skillsize > MaxSkillsPerPage * MaxPages)
  1231. MaxPages++;
  1232. if (page > MaxPages)
  1233. page = MaxPages;
  1234. int SkillsStart = MaxSkillsPerPage * page;
  1235. int SkillsEnd = _skillsize;
  1236. if (SkillsEnd - SkillsStart > MaxSkillsPerPage)
  1237. SkillsEnd = SkillsStart + MaxSkillsPerPage;
  1238. StringBuffer replyMSG = new StringBuffer("<html><title>Show NPC Skill List</title><body><center><font color=\"LEVEL\">");
  1239. replyMSG.append(npcData.getName());
  1240. replyMSG.append(" (");
  1241. replyMSG.append(npcData.getNpcId());
  1242. replyMSG.append("): ");
  1243. replyMSG.append(_skillsize);
  1244. replyMSG.append(" skills</font></center><table width=300 bgcolor=666666><tr>");
  1245. for (int x = 0; x < MaxPages; x++)
  1246. {
  1247. int pagenr = x + 1;
  1248. if (page == x)
  1249. {
  1250. replyMSG.append("<td>Page ");
  1251. replyMSG.append(pagenr);
  1252. replyMSG.append("</td>");
  1253. }
  1254. else
  1255. {
  1256. replyMSG.append("<td><a action=\"bypass -h admin_show_skilllist_npc ");
  1257. replyMSG.append(npcData.getNpcId());
  1258. replyMSG.append(" ");
  1259. replyMSG.append(x);
  1260. replyMSG.append("\"> Page ");
  1261. replyMSG.append(pagenr);
  1262. replyMSG.append(" </a></td>");
  1263. }
  1264. }
  1265. replyMSG.append("</tr></table><table width=\"100%\" border=0><tr><td>Skill name [skill id-skill lvl]</td><td>Delete</td></tr>");
  1266. Iterator<L2Skill> skillite = skills.values().iterator();
  1267. for (int i = 0; i < SkillsStart; i++)
  1268. {
  1269. if (skillite.hasNext())
  1270. skillite.next();
  1271. }
  1272. int cnt = SkillsStart;
  1273. L2Skill sk;
  1274. while (skillite.hasNext())
  1275. {
  1276. cnt++;
  1277. if (cnt > SkillsEnd)
  1278. break;
  1279. sk = skillite.next();
  1280. replyMSG.append("<tr><td width=240><a action=\"bypass -h admin_edit_skill_npc ");
  1281. replyMSG.append(npcData.getNpcId());
  1282. replyMSG.append(" ");
  1283. replyMSG.append(sk.getId());
  1284. replyMSG.append("\">");
  1285. if (sk.getSkillType() == L2SkillType.NOTDONE)
  1286. replyMSG.append("<font color=\"777777\">" + sk.getName() + "</font>");
  1287. else
  1288. replyMSG.append(sk.getName());
  1289. replyMSG.append(" [");
  1290. replyMSG.append(sk.getId());
  1291. replyMSG.append("-");
  1292. replyMSG.append(sk.getLevel());
  1293. replyMSG.append("]</a></td><td width=60><a action=\"bypass -h admin_del_skill_npc ");
  1294. replyMSG.append(npcData.getNpcId());
  1295. replyMSG.append(" ");
  1296. replyMSG.append(sk.getId());
  1297. replyMSG.append("\">Delete</a></td></tr>");
  1298. }
  1299. replyMSG.append("</table><br><center><button value=\"Add Skill\" action=\"bypass -h admin_add_skill_npc ");
  1300. replyMSG.append(npcId);
  1301. 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>");
  1302. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1303. adminReply.setHtml(replyMSG.toString());
  1304. activeChar.sendPacket(adminReply);
  1305. }
  1306. private void showNpcSkillEdit(L2PcInstance activeChar, int npcId, int skillId)
  1307. {
  1308. try
  1309. {
  1310. StringBuffer replyMSG = new StringBuffer("<html><title>NPC Skill Edit</title><body>");
  1311. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1312. if (npcData == null)
  1313. {
  1314. activeChar.sendMessage("Template id unknown: " + npcId);
  1315. return;
  1316. }
  1317. if (npcData.getSkills() == null)
  1318. return;
  1319. L2Skill npcSkill = npcData.getSkills().get(skillId);
  1320. if (npcSkill != null)
  1321. {
  1322. replyMSG.append("<table width=\"100%\"><tr><td>NPC: </td><td>");
  1323. replyMSG.append(NpcTable.getInstance().getTemplate(npcId).getName());
  1324. replyMSG.append(" (");
  1325. replyMSG.append(npcId);
  1326. replyMSG.append(")</td></tr><tr><td>Skill: </td><td>");
  1327. replyMSG.append(npcSkill.getName());
  1328. replyMSG.append(" (");
  1329. replyMSG.append(skillId);
  1330. replyMSG.append(")</td></tr><tr><td>Skill Lvl: (");
  1331. replyMSG.append(npcSkill.getLevel());
  1332. replyMSG.append(") </td><td><edit var=\"level\" width=50></td></tr></table><br><center><button value=\"Save\" action=\"bypass -h admin_edit_skill_npc ");
  1333. replyMSG.append(npcId);
  1334. replyMSG.append(" ");
  1335. replyMSG.append(skillId);
  1336. 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 ");
  1337. replyMSG.append(npcId);
  1338. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center>");
  1339. }
  1340. replyMSG.append("</body></html>");
  1341. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1342. adminReply.setHtml(replyMSG.toString());
  1343. activeChar.sendPacket(adminReply);
  1344. }
  1345. catch (Exception e)
  1346. {
  1347. activeChar.sendMessage("Could not edit npc skills!");
  1348. _log.warning("Error while editing npc skills (" + npcId + ", " + skillId + "): " + e);
  1349. }
  1350. }
  1351. private void updateNpcSkillData(L2PcInstance activeChar, int npcId, int skillId, int level)
  1352. {
  1353. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1354. {
  1355. L2Skill skillData = SkillTable.getInstance().getInfo(skillId, level);
  1356. if (skillData == null)
  1357. {
  1358. activeChar.sendMessage("Could not update npc skill: not existing skill id with that level!");
  1359. showNpcSkillEdit(activeChar, npcId, skillId);
  1360. return;
  1361. }
  1362. if (skillData.getLevel() != level)
  1363. {
  1364. activeChar.sendMessage("Skill id with requested level doesn't exist! Skill level not changed.");
  1365. showNpcSkillEdit(activeChar, npcId, skillId);
  1366. return;
  1367. }
  1368. int updated = 0;
  1369. if(Config.CUSTOM_NPC_SKILLS_TABLE)
  1370. {
  1371. PreparedStatement statement2 = con.prepareStatement("UPDATE `custom_npcskills` SET `level`=? WHERE `npcid`=? AND `skillid`=?");
  1372. statement2.setInt(1, level);
  1373. statement2.setInt(2, npcId);
  1374. statement2.setInt(3, skillId);
  1375. updated = statement2.executeUpdate();
  1376. statement2.close();
  1377. }
  1378. if(updated == 0)
  1379. {
  1380. PreparedStatement statement = con.prepareStatement("UPDATE `npcskills` SET `level`=? WHERE `npcid`=? AND `skillid`=?");
  1381. statement.setInt(1, level);
  1382. statement.setInt(2, npcId);
  1383. statement.setInt(3, skillId);
  1384. statement.execute();
  1385. statement.close();
  1386. }
  1387. reloadNpcSkillList(npcId);
  1388. showNpcSkillList(activeChar, npcId, 0);
  1389. activeChar.sendMessage("Updated skill id " + skillId + " for npc id " + npcId + " to level " + level + ".");
  1390. }
  1391. catch (Exception e)
  1392. {
  1393. activeChar.sendMessage("Could not update npc skill!");
  1394. _log.warning("Error while updating npc skill (" + npcId + ", " + skillId + ", " + level + "): " + e);
  1395. }
  1396. }
  1397. private void showNpcSkillAdd(L2PcInstance activeChar, int npcId)
  1398. {
  1399. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1400. StringBuffer replyMSG = new StringBuffer("<html><title>NPC Skill Add</title><body><table width=\"100%\"><tr><td>NPC: </td><td>");
  1401. replyMSG.append(npcData.getName());
  1402. replyMSG.append(" (");
  1403. replyMSG.append(npcData.getNpcId());
  1404. 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 ");
  1405. replyMSG.append(npcData.getNpcId());
  1406. 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 ");
  1407. replyMSG.append(npcData.getNpcId());
  1408. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1409. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1410. adminReply.setHtml(replyMSG.toString());
  1411. activeChar.sendPacket(adminReply);
  1412. }
  1413. private void addNpcSkillData(L2PcInstance activeChar, int npcId, int skillId, int level)
  1414. {
  1415. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1416. {
  1417. // skill check
  1418. L2Skill skillData = SkillTable.getInstance().getInfo(skillId, level);
  1419. if (skillData == null)
  1420. {
  1421. activeChar.sendMessage("Could not add npc skill: not existing skill id with that level!");
  1422. showNpcSkillAdd(activeChar, npcId);
  1423. return;
  1424. }
  1425. if (Config.CUSTOM_NPC_SKILLS_TABLE)
  1426. {
  1427. PreparedStatement statement = con.prepareStatement("INSERT INTO `custom_npcskills`(`npcid`, `skillid`, `level`) VALUES(?,?,?)");
  1428. statement.setInt(1, npcId);
  1429. statement.setInt(2, skillId);
  1430. statement.setInt(3, level);
  1431. statement.execute();
  1432. statement.close();
  1433. }
  1434. else
  1435. {
  1436. PreparedStatement statement = con.prepareStatement("INSERT INTO `npcskills`(`npcid`, `skillid`, `level`) VALUES(?,?,?)");
  1437. statement.setInt(1, npcId);
  1438. statement.setInt(2, skillId);
  1439. statement.setInt(3, level);
  1440. statement.execute();
  1441. statement.close();
  1442. }
  1443. reloadNpcSkillList(npcId);
  1444. showNpcSkillList(activeChar, npcId, 0);
  1445. activeChar.sendMessage("Added skill " + skillId + "-" + level + " to npc id " + npcId + ".");
  1446. }
  1447. catch (Exception e)
  1448. {
  1449. activeChar.sendMessage("Could not add npc skill!");
  1450. _log.warning("Error while adding a npc skill (" + npcId + ", " + skillId + ", " + level + "): " + e);
  1451. }
  1452. }
  1453. private void deleteNpcSkillData(L2PcInstance activeChar, int npcId, int skillId)
  1454. {
  1455. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1456. {
  1457. if (npcId > 0)
  1458. {
  1459. int updated = 0;
  1460. if (Config.CUSTOM_NPC_SKILLS_TABLE)
  1461. {
  1462. PreparedStatement statement = con.prepareStatement("DELETE FROM `custom_npcskills` WHERE `npcid`=? AND `skillid`=?");
  1463. statement.setInt(1, npcId);
  1464. statement.setInt(2, skillId);
  1465. updated = statement.executeUpdate();
  1466. statement.close();
  1467. }
  1468. if (updated == 0)
  1469. {
  1470. PreparedStatement statement2 = con.prepareStatement("DELETE FROM `npcskills` WHERE `npcid`=? AND `skillid`=?");
  1471. statement2.setInt(1, npcId);
  1472. statement2.setInt(2, skillId);
  1473. statement2.execute();
  1474. statement2.close();
  1475. }
  1476. reloadNpcSkillList(npcId);
  1477. showNpcSkillList(activeChar, npcId, 0);
  1478. activeChar.sendMessage("Deleted skill id " + skillId + " from npc id " + npcId + ".");
  1479. }
  1480. }
  1481. catch (Exception e)
  1482. {
  1483. activeChar.sendMessage("Could not delete npc skill!");
  1484. _log.warning("Error while deleting npc skill (" + npcId + ", " + skillId + "): " + e);
  1485. }
  1486. }
  1487. private void reloadNpcSkillList(int npcId)
  1488. {
  1489. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1490. {
  1491. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1492. L2Skill skillData = null;
  1493. if (npcData.getSkills() != null)
  1494. npcData.getSkills().clear();
  1495. // without race
  1496. PreparedStatement statement = con.prepareStatement("SELECT `skillid`, `level` FROM `npcskills` WHERE `npcid`=? AND `skillid` <> 4416");
  1497. statement.setInt(1, npcId);
  1498. ResultSet skillDataList = statement.executeQuery();
  1499. while (skillDataList.next())
  1500. {
  1501. int idval = skillDataList.getInt("skillid");
  1502. int levelval = skillDataList.getInt("level");
  1503. skillData = SkillTable.getInstance().getInfo(idval, levelval);
  1504. if (skillData != null)
  1505. npcData.addSkill(skillData);
  1506. }
  1507. skillDataList.close();
  1508. statement.close();
  1509. if (Config.CUSTOM_NPC_SKILLS_TABLE)
  1510. {
  1511. PreparedStatement statement2 = con.prepareStatement("SELECT `skillid`, `level` FROM `npcskills` WHERE `npcid`=? AND `skillid` <> 4416");
  1512. statement2.setInt(1, npcId);
  1513. ResultSet skillDataList2 = statement2.executeQuery();
  1514. while (skillDataList2.next())
  1515. {
  1516. int idval = skillDataList2.getInt("skillid");
  1517. int levelval = skillDataList2.getInt("level");
  1518. skillData = SkillTable.getInstance().getInfo(idval, levelval);
  1519. if (skillData != null)
  1520. npcData.addSkill(skillData);
  1521. }
  1522. skillDataList2.close();
  1523. statement2.close();
  1524. }
  1525. }
  1526. catch (Exception e)
  1527. {
  1528. _log.warning("Error while reloading npc skill list (" + npcId + "): " + e);
  1529. }
  1530. }
  1531. }