AdminEditNpc.java 59 KB

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