Advertisement
Guest User

Auction shop

a guest
Jan 24th, 2017
3,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.78 KB | None | 0 0
  1. Index: java/net/sf/l2j/gameserver/GameServer.java
  2. ===================================================================
  3. --- java/net/sf/l2j/gameserver/GameServer.java (revision 21)
  4. +++ java/net/sf/l2j/gameserver/GameServer.java (working copy)
  5. @@ -75,6 +75,7 @@
  6. import net.sf.l2j.gameserver.instancemanager.PetitionManager;
  7. import net.sf.l2j.gameserver.instancemanager.ZoneManager;
  8. import net.sf.l2j.gameserver.l2spike.botengine.BotManager;
  9. +import net.sf.l2j.gameserver.l2spike.datatables.AuctionTable;
  10. import net.sf.l2j.gameserver.l2spike.datatables.IconTable;
  11. import net.sf.l2j.gameserver.l2spike.handler.BypassHandler;
  12. import net.sf.l2j.gameserver.l2spike.partymatching.PartyMatchingManager;
  13. @@ -226,6 +227,7 @@
  14. IconTable.getInstance();
  15. BotManager.getInstance();
  16. PartyMatchingManager.getInstance();
  17. + AuctionTable.getInstance();
  18.  
  19. StringUtil.printSection("System");
  20. Runtime.getRuntime().addShutdownHook(Shutdown.getInstance());
  21. Index: java/net/sf/l2j/gameserver/l2spike/auction/AuctionItem.java
  22. ===================================================================
  23. --- java/net/sf/l2j/gameserver/l2spike/auction/AuctionItem.java (revision 0)
  24. +++ java/net/sf/l2j/gameserver/l2spike/auction/AuctionItem.java (revision 0)
  25. @@ -0,0 +1,76 @@
  26. +/*
  27. + * This program is free software: you can redistribute it and/or modify it under
  28. + * the terms of the GNU General Public License as published by the Free Software
  29. + * Foundation, either version 3 of the License, or (at your option) any later
  30. + * version.
  31. + *
  32. + * This program is distributed in the hope that it will be useful, but WITHOUT
  33. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  34. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  35. + * details.
  36. + *
  37. + * You should have received a copy of the GNU General Public License along with
  38. + * this program. If not, see <http://www.gnu.org/licenses/>.
  39. + */
  40. +package net.sf.l2j.gameserver.l2spike.auction;
  41. +
  42. +/**
  43. + * @author Anarchy
  44. + *
  45. + */
  46. +public class AuctionItem
  47. +{
  48. + private int auctionId;
  49. + private int ownerId;
  50. + private int itemId;
  51. + private int count;
  52. + private int enchant;
  53. + private int costId;
  54. + private int costCount;
  55. +
  56. + public AuctionItem(int auctionId, int ownerId, int itemId, int count, int enchant, int costId, int costCount)
  57. + {
  58. + this.auctionId = auctionId;
  59. + this.ownerId = ownerId;
  60. + this.itemId = itemId;
  61. + this.count = count;
  62. + this.enchant = enchant;
  63. + this.costId = costId;
  64. + this.costCount = costCount;
  65. + }
  66. +
  67. + public int getAuctionId()
  68. + {
  69. + return auctionId;
  70. + }
  71. +
  72. + public int getOwnerId()
  73. + {
  74. + return ownerId;
  75. + }
  76. +
  77. + public int getItemId()
  78. + {
  79. + return itemId;
  80. + }
  81. +
  82. + public int getCount()
  83. + {
  84. + return count;
  85. + }
  86. +
  87. + public int getEnchant()
  88. + {
  89. + return enchant;
  90. + }
  91. +
  92. + public int getCostId()
  93. + {
  94. + return costId;
  95. + }
  96. +
  97. + public int getCostCount()
  98. + {
  99. + return costCount;
  100. + }
  101. +}
  102. Index: java/net/sf/l2j/gameserver/l2spike/datatables/AuctionTable.java
  103. ===================================================================
  104. --- java/net/sf/l2j/gameserver/l2spike/datatables/AuctionTable.java (revision 0)
  105. +++ java/net/sf/l2j/gameserver/l2spike/datatables/AuctionTable.java (revision 0)
  106. @@ -0,0 +1,199 @@
  107. +/*
  108. + * This program is free software: you can redistribute it and/or modify it under
  109. + * the terms of the GNU General Public License as published by the Free Software
  110. + * Foundation, either version 3 of the License, or (at your option) any later
  111. + * version.
  112. + *
  113. + * This program is distributed in the hope that it will be useful, but WITHOUT
  114. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  115. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  116. + * details.
  117. + *
  118. + * You should have received a copy of the GNU General Public License along with
  119. + * this program. If not, see <http://www.gnu.org/licenses/>.
  120. + */
  121. +package net.sf.l2j.gameserver.l2spike.datatables;
  122. +
  123. +import java.sql.Connection;
  124. +import java.sql.PreparedStatement;
  125. +import java.sql.ResultSet;
  126. +import java.util.ArrayList;
  127. +import java.util.logging.Logger;
  128. +
  129. +import net.sf.l2j.L2DatabaseFactory;
  130. +import net.sf.l2j.gameserver.l2spike.auction.AuctionItem;
  131. +
  132. +/**
  133. + * @author Anarchy
  134. + *
  135. + */
  136. +public class AuctionTable
  137. +{
  138. + private static Logger log = Logger.getLogger(AuctionTable.class.getName());
  139. +
  140. + private ArrayList<AuctionItem> items;
  141. + private int maxId;
  142. +
  143. + public static AuctionTable getInstance()
  144. + {
  145. + return SingletonHolder._instance;
  146. + }
  147. +
  148. + protected AuctionTable()
  149. + {
  150. + items = new ArrayList<>();
  151. + maxId = 0;
  152. +
  153. + load();
  154. + }
  155. +
  156. + private void load()
  157. + {
  158. + Connection con = null;
  159. + try
  160. + {
  161. + con = L2DatabaseFactory.getInstance().getConnection();
  162. + PreparedStatement stm = con.prepareStatement("SELECT * FROM auction_table");
  163. + ResultSet rset = stm.executeQuery();
  164. +
  165. + while (rset.next())
  166. + {
  167. + int auctionId = rset.getInt("auctionid");
  168. + int ownerId = rset.getInt("ownerid");
  169. + int itemId = rset.getInt("itemid");
  170. + int count = rset.getInt("count");
  171. + int enchant = rset.getInt("enchant");
  172. + int costId = rset.getInt("costid");
  173. + int costCount = rset.getInt("costcount");
  174. +
  175. + items.add(new AuctionItem(auctionId, ownerId, itemId, count, enchant, costId, costCount));
  176. +
  177. + if (auctionId > maxId)
  178. + maxId = auctionId;
  179. + }
  180. +
  181. + rset.close();
  182. + stm.close();
  183. + }
  184. + catch (Exception e)
  185. + {
  186. + e.printStackTrace();
  187. + }
  188. + finally
  189. + {
  190. + try
  191. + {
  192. + if (con != null)
  193. + con.close();
  194. + }
  195. + catch (Exception e)
  196. + {
  197. + e.printStackTrace();
  198. + }
  199. + }
  200. +
  201. + log.info("AuctionTable: Loaded "+items.size()+" items.");
  202. + }
  203. +
  204. + public void addItem(AuctionItem item)
  205. + {
  206. + items.add(item);
  207. +
  208. + Connection con = null;
  209. + try
  210. + {
  211. + con = L2DatabaseFactory.getInstance().getConnection();
  212. + PreparedStatement stm = con.prepareStatement("INSERT INTO auction_table VALUES (?,?,?,?,?,?,?)");
  213. + stm.setInt(1, item.getAuctionId());
  214. + stm.setInt(2, item.getOwnerId());
  215. + stm.setInt(3, item.getItemId());
  216. + stm.setInt(4, item.getCount());
  217. + stm.setInt(5, item.getEnchant());
  218. + stm.setInt(6, item.getCostId());
  219. + stm.setInt(7, item.getCostCount());
  220. +
  221. + stm.execute();
  222. + stm.close();
  223. + }
  224. + catch (Exception e)
  225. + {
  226. + e.printStackTrace();
  227. + }
  228. + finally
  229. + {
  230. + try
  231. + {
  232. + if (con != null)
  233. + con.close();
  234. + }
  235. + catch (Exception e)
  236. + {
  237. + e.printStackTrace();
  238. + }
  239. + }
  240. + }
  241. +
  242. + public void deleteItem(AuctionItem item)
  243. + {
  244. + items.remove(item);
  245. +
  246. + Connection con = null;
  247. + try
  248. + {
  249. + con = L2DatabaseFactory.getInstance().getConnection();
  250. + PreparedStatement stm = con.prepareStatement("DELETE FROM auction_table WHERE auctionid=?");
  251. + stm.setInt(1, item.getAuctionId());
  252. +
  253. + stm.execute();
  254. + stm.close();
  255. + }
  256. + catch (Exception e)
  257. + {
  258. + e.printStackTrace();
  259. + }
  260. + finally
  261. + {
  262. + try
  263. + {
  264. + if (con != null)
  265. + con.close();
  266. + }
  267. + catch (Exception e)
  268. + {
  269. + e.printStackTrace();
  270. + }
  271. + }
  272. + }
  273. +
  274. + public AuctionItem getItem(int auctionId)
  275. + {
  276. + AuctionItem ret = null;
  277. +
  278. + for (AuctionItem item : items)
  279. + {
  280. + if (item.getAuctionId() == auctionId)
  281. + {
  282. + ret = item;
  283. + break;
  284. + }
  285. + }
  286. +
  287. + return ret;
  288. + }
  289. +
  290. + public ArrayList<AuctionItem> getItems()
  291. + {
  292. + return items;
  293. + }
  294. +
  295. + public int getNextAuctionId()
  296. + {
  297. + maxId++;
  298. + return maxId;
  299. + }
  300. +
  301. + private static class SingletonHolder
  302. + {
  303. + protected static final AuctionTable _instance = new AuctionTable();
  304. + }
  305. +}
  306. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2AuctionManagerInstance.java
  307. ===================================================================
  308. --- java/net/sf/l2j/gameserver/model/actor/instance/L2AuctionManagerInstance.java (revision 0)
  309. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2AuctionManagerInstance.java (revision 0)
  310. @@ -0,0 +1,512 @@
  311. +/*
  312. + * This program is free software: you can redistribute it and/or modify it under
  313. + * the terms of the GNU General Public License as published by the Free Software
  314. + * Foundation, either version 3 of the License, or (at your option) any later
  315. + * version.
  316. + *
  317. + * This program is distributed in the hope that it will be useful, but WITHOUT
  318. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  319. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  320. + * details.
  321. + *
  322. + * You should have received a copy of the GNU General Public License along with
  323. + * this program. If not, see <http://www.gnu.org/licenses/>.
  324. + */
  325. +package net.sf.l2j.gameserver.model.actor.instance;
  326. +
  327. +import java.sql.Connection;
  328. +import java.sql.PreparedStatement;
  329. +import java.sql.ResultSet;
  330. +import java.util.ArrayList;
  331. +import java.util.HashMap;
  332. +
  333. +import net.sf.l2j.L2DatabaseFactory;
  334. +import net.sf.l2j.gameserver.datatables.ItemTable;
  335. +import net.sf.l2j.gameserver.idfactory.IdFactory;
  336. +import net.sf.l2j.gameserver.l2spike.auction.AuctionItem;
  337. +import net.sf.l2j.gameserver.l2spike.datatables.AuctionTable;
  338. +import net.sf.l2j.gameserver.l2spike.datatables.IconTable;
  339. +import net.sf.l2j.gameserver.model.World;
  340. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  341. +import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
  342. +import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
  343. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  344. +
  345. +/**
  346. + * @author Anarchy
  347. + *
  348. + */
  349. +public class L2AuctionManagerInstance extends L2NpcInstance
  350. +{
  351. + public L2AuctionManagerInstance(int objectId, NpcTemplate template)
  352. + {
  353. + super(objectId, template);
  354. + }
  355. +
  356. + @Override
  357. + public void onBypassFeedback(L2PcInstance player, String command)
  358. + {
  359. + if (command.startsWith("auction"))
  360. + {
  361. + try
  362. + {
  363. + String[] data = command.substring(8).split(" - ");
  364. + int page = Integer.parseInt(data[0]);
  365. + String search = data[1];
  366. + showAuction(player, page, search);
  367. + }
  368. + catch (Exception e)
  369. + {
  370. + showChatWindow(player);
  371. + player.sendMessage("Invalid input. Please try again.");
  372. + return;
  373. + }
  374. + }
  375. + else if (command.startsWith("buy"))
  376. + {
  377. + int auctionId = Integer.parseInt(command.substring(4));
  378. + AuctionItem item = AuctionTable.getInstance().getItem(auctionId);
  379. +
  380. + if (item == null)
  381. + {
  382. + showChatWindow(player);
  383. + player.sendMessage("Invalid choice. Please try again.");
  384. + return;
  385. + }
  386. +
  387. + if (player.getInventory().getItemByItemId(item.getCostId()) == null || player.getInventory().getItemByItemId(item.getCostId()).getCount() < item.getCostCount())
  388. + {
  389. + showChatWindow(player);
  390. + player.sendMessage("Incorrect item count.");
  391. + return;
  392. + }
  393. +
  394. + player.destroyItemByItemId("auction", item.getCostId(), item.getCostCount(), this, true);
  395. +
  396. + L2PcInstance owner = World.getInstance().getPlayer(item.getOwnerId());
  397. + if (owner != null && owner.isOnline())
  398. + {
  399. + owner.addItem("auction", item.getCostId(), item.getCostCount(), null, true);
  400. + owner.sendMessage("You have sold an item in the Auction Shop.");
  401. + }
  402. + else
  403. + {
  404. + addItemToOffline(item.getOwnerId(), item.getCostId(), item.getCostCount());
  405. + }
  406. +
  407. + ItemInstance i = player.addItem("auction", item.getItemId(), item.getCount(), this, true);
  408. + i.setEnchantLevel(item.getEnchant());
  409. + player.sendPacket(new InventoryUpdate());
  410. + player.sendMessage("You have purchased an item from the Auction Shop.");
  411. +
  412. + AuctionTable.getInstance().deleteItem(item);
  413. +
  414. + showChatWindow(player);
  415. + }
  416. + else if (command.startsWith("addpanel"))
  417. + {
  418. + int page = Integer.parseInt(command.substring(9));
  419. +
  420. + showAddPanel(player, page);
  421. + }
  422. + else if (command.startsWith("additem"))
  423. + {
  424. + int itemId = Integer.parseInt(command.substring(8));
  425. +
  426. + if (player.getInventory().getItemByObjectId(itemId) == null)
  427. + {
  428. + showChatWindow(player);
  429. + player.sendMessage("Invalid item. Please try again.");
  430. + return;
  431. + }
  432. +
  433. + showAddPanel2(player, itemId);
  434. + }
  435. + else if (command.startsWith("addit2"))
  436. + {
  437. + try
  438. + {
  439. + String[] data = command.substring(7).split(" ");
  440. + int itemId = Integer.parseInt(data[0]);
  441. + String costitemtype = data[1];
  442. + int costCount = Integer.parseInt(data[2]);
  443. + int itemAmount = Integer.parseInt(data[3]);
  444. +
  445. + if (player.getInventory().getItemByObjectId(itemId) == null)
  446. + {
  447. + showChatWindow(player);
  448. + player.sendMessage("Invalid item. Please try again.");
  449. + return;
  450. + }
  451. + if (player.getInventory().getItemByObjectId(itemId).getCount() < itemAmount)
  452. + {
  453. + showChatWindow(player);
  454. + player.sendMessage("Invalid item. Please try again.");
  455. + return;
  456. + }
  457. + if (!player.getInventory().getItemByObjectId(itemId).isTradable())
  458. + {
  459. + showChatWindow(player);
  460. + player.sendMessage("Invalid item. Please try again.");
  461. + return;
  462. + }
  463. +
  464. + int costId = 0;
  465. + if (costitemtype.equals("Adena"))
  466. + {
  467. + costId = 57;
  468. + }
  469. +
  470. + AuctionTable.getInstance().addItem(new AuctionItem(AuctionTable.getInstance().getNextAuctionId(), player.getObjectId(), player.getInventory().getItemByObjectId(itemId).getItemId(), itemAmount, player.getInventory().getItemByObjectId(itemId).getEnchantLevel(), costId, costCount));
  471. +
  472. + player.destroyItem("auction", itemId, itemAmount, this, true);
  473. + player.sendPacket(new InventoryUpdate());
  474. + player.sendMessage("You have added an item for sale in the Auction Shop.");
  475. + showChatWindow(player);
  476. + }
  477. + catch (Exception e)
  478. + {
  479. + showChatWindow(player);
  480. + player.sendMessage("Invalid input. Please try again.");
  481. + return;
  482. + }
  483. + }
  484. + else if (command.startsWith("myitems"))
  485. + {
  486. + int page = Integer.parseInt(command.substring(8));
  487. + showMyItems(player, page);
  488. + }
  489. + else if (command.startsWith("remove"))
  490. + {
  491. + int auctionId = Integer.parseInt(command.substring(7));
  492. + AuctionItem item = AuctionTable.getInstance().getItem(auctionId);
  493. +
  494. + if (item == null)
  495. + {
  496. + showChatWindow(player);
  497. + player.sendMessage("Invalid choice. Please try again.");
  498. + return;
  499. + }
  500. +
  501. + AuctionTable.getInstance().deleteItem(item);
  502. +
  503. + ItemInstance i = player.addItem("auction", item.getItemId(), item.getCount(), this, true);
  504. + i.setEnchantLevel(item.getEnchant());
  505. + player.sendPacket(new InventoryUpdate());
  506. + player.sendMessage("You have removed an item from the Auction Shop.");
  507. + showChatWindow(player);
  508. + }
  509. + else
  510. + {
  511. + super.onBypassFeedback(player, command);
  512. + }
  513. + }
  514. +
  515. + private void showMyItems(L2PcInstance player, int page)
  516. + {
  517. + HashMap<Integer, ArrayList<AuctionItem>> items = new HashMap<>();
  518. + int curr = 1;
  519. + int counter = 0;
  520. +
  521. + ArrayList<AuctionItem> temp = new ArrayList<>();
  522. + for (AuctionItem item : AuctionTable.getInstance().getItems())
  523. + {
  524. + if (item.getOwnerId() == player.getObjectId())
  525. + {
  526. + temp.add(item);
  527. +
  528. + counter++;
  529. +
  530. + if (counter == 10)
  531. + {
  532. + items.put(curr, temp);
  533. + temp = new ArrayList<>();
  534. + curr++;
  535. + counter = 0;
  536. + }
  537. + }
  538. + }
  539. + items.put(curr, temp);
  540. +
  541. + if (!items.containsKey(page))
  542. + {
  543. + showChatWindow(player);
  544. + player.sendMessage("Invalid page. Please try again.");
  545. + return;
  546. + }
  547. +
  548. + String html = "";
  549. + html += "<html><title>Auction Shop</title><body><center><br1>";
  550. + html += "<table width=310 bgcolor=000000 border=1>";
  551. + html += "<tr><td>Item</td><td>Cost</td><td></td></tr>";
  552. + for (AuctionItem item : items.get(page))
  553. + {
  554. + html += "<tr>";
  555. + html += "<td><img src=\""+IconTable.getInstance().getIcon(item.getItemId())+"\" width=32 height=32 align=center></td>";
  556. + html += "<td>Item: "+(item.getEnchant() > 0 ? "+"+item.getEnchant()+" "+ItemTable.getInstance().getTemplate(item.getItemId()).getName()+" - "+item.getCount() : ItemTable.getInstance().getTemplate(item.getItemId()).getName()+" - "+item.getCount());
  557. + html += "<br1>Cost: "+item.getCostCount()+" "+ItemTable.getInstance().getTemplate(item.getCostId()).getName();
  558. + html += "</td>";
  559. + html += "<td fixwidth=71><button value=\"Remove\" action=\"bypass -h npc_"+getObjectId()+"_remove "+item.getAuctionId()+"\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\">";
  560. + html += "</td></tr>";
  561. + }
  562. + html += "</table><br><br>";
  563. +
  564. + html += "Page: "+page;
  565. + html += "<br1>";
  566. +
  567. + if (items.keySet().size() > 1)
  568. + {
  569. + if (page > 1)
  570. + html += "<a action=\"bypass -h npc_"+getObjectId()+"_myitems "+(page-1)+"\"><- Prev</a>";
  571. +
  572. + if (items.keySet().size() > page)
  573. + html += "<a action=\"bypass -h npc_"+getObjectId()+"_myitems "+(page+1)+"\">Next -></a>";
  574. + }
  575. +
  576. + html += "</center></body></html>";
  577. +
  578. + NpcHtmlMessage htm = new NpcHtmlMessage(getObjectId());
  579. + htm.setHtml(html);
  580. + player.sendPacket(htm);
  581. + }
  582. +
  583. + private void showAddPanel2(L2PcInstance player, int itemId)
  584. + {
  585. + ItemInstance item = player.getInventory().getItemByObjectId(itemId);
  586. +
  587. + String html = "";
  588. + html += "<html><title>Auction Shop</title><body><center><br1>";
  589. + html += "<img src=\""+IconTable.getInstance().getIcon(item.getItemId())+"\" width=32 height=32 align=center>";
  590. + html += "Item: "+(item.getEnchantLevel() > 0 ? "+"+item.getEnchantLevel()+" "+item.getName() : item.getName());
  591. +
  592. + if (item.isStackable())
  593. + {
  594. + html += "<br>Set amount of items to sell:";
  595. + html += "<edit var=amm type=number width=120 height=17>";
  596. + }
  597. +
  598. + html += "<br>Select price:";
  599. + html += "<br><combobox width=120 height=17 var=ebox list=Adena;>";
  600. + html += "<br><edit var=count type=number width=120 height=17>";
  601. + html += "<br><button value=\"Add item\" action=\"bypass -h npc_"+getObjectId()+"_addit2 "+itemId+" $ebox $count "+(item.isStackable() ? "$amm" : "1")+"\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\">";
  602. + html += "</center></body></html>";
  603. +
  604. + NpcHtmlMessage htm = new NpcHtmlMessage(getObjectId());
  605. + htm.setHtml(html);
  606. + player.sendPacket(htm);
  607. + }
  608. +
  609. + private void showAddPanel(L2PcInstance player, int page)
  610. + {
  611. + HashMap<Integer, ArrayList<ItemInstance>> items = new HashMap<>();
  612. + int curr = 1;
  613. + int counter = 0;
  614. +
  615. + ArrayList<ItemInstance> temp = new ArrayList<>();
  616. + for (ItemInstance item : player.getInventory().getItems())
  617. + {
  618. + if (item.getItemId() != 57 && item.isTradable())
  619. + {
  620. + temp.add(item);
  621. +
  622. + counter++;
  623. +
  624. + if (counter == 10)
  625. + {
  626. + items.put(curr, temp);
  627. + temp = new ArrayList<>();
  628. + curr++;
  629. + counter = 0;
  630. + }
  631. + }
  632. + }
  633. + items.put(curr, temp);
  634. +
  635. + if (!items.containsKey(page))
  636. + {
  637. + showChatWindow(player);
  638. + player.sendMessage("Invalid page. Please try again.");
  639. + return;
  640. + }
  641. +
  642. + String html = "";
  643. + html += "<html><title>Auction Shop</title><body><center><br1>";
  644. + html += "Select item:";
  645. + html += "<br><table width=310 bgcolor=000000 border=1>";
  646. +
  647. + for (ItemInstance item : items.get(page))
  648. + {
  649. + html += "<tr>";
  650. + html += "<td>";
  651. + html += "<img src=\""+IconTable.getInstance().getIcon(item.getItemId())+"\" width=32 height=32 align=center></td>";
  652. + html += "<td>"+(item.getEnchantLevel() > 0 ? "+"+item.getEnchantLevel()+" "+item.getName() : item.getName());
  653. + html += "</td>";
  654. + html += "<td><button value=\"Select\" action=\"bypass -h npc_"+getObjectId()+"_additem "+item.getObjectId()+"\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\">";
  655. + html += "</td>";
  656. + html += "</tr>";
  657. + }
  658. + html += "</table><br><br>";
  659. +
  660. + html += "Page: "+page;
  661. + html += "<br1>";
  662. +
  663. + if (items.keySet().size() > 1)
  664. + {
  665. + if (page > 1)
  666. + html += "<a action=\"bypass -h npc_"+getObjectId()+"_addpanel "+(page-1)+"\"><- Prev</a>";
  667. +
  668. + if (items.keySet().size() > page)
  669. + html += "<a action=\"bypass -h npc_"+getObjectId()+"_addpanel "+(page+1)+"\">Next -></a>";
  670. + }
  671. +
  672. + html += "</center></body></html>";
  673. +
  674. + NpcHtmlMessage htm = new NpcHtmlMessage(getObjectId());
  675. + htm.setHtml(html);
  676. + player.sendPacket(htm);
  677. + }
  678. +
  679. + @SuppressWarnings("resource")
  680. + private static void addItemToOffline(int playerId, int itemId, int count)
  681. + {
  682. + Connection con = null;
  683. + try
  684. + {
  685. + con = L2DatabaseFactory.getInstance().getConnection();
  686. + PreparedStatement stm = con.prepareStatement("SELECT count FROM items WHERE owner_id=? AND item_id=?");
  687. + stm.setInt(1, playerId);
  688. + stm.setInt(2, itemId);
  689. + ResultSet rset = stm.executeQuery();
  690. +
  691. + if (rset.next())
  692. + {
  693. + stm = con.prepareStatement("UPDATE items SET count=? WHERE owner_id=? AND item_id=?");
  694. + stm.setInt(1, rset.getInt("count") + count);
  695. + stm.setInt(2, playerId);
  696. + stm.setInt(3, itemId);
  697. +
  698. + stm.execute();
  699. + }
  700. + else
  701. + {
  702. + stm = con.prepareStatement("INSERT INTO items VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");
  703. + stm.setInt(1, playerId);
  704. + stm.setInt(2, IdFactory.getInstance().getNextId());
  705. + stm.setInt(3, itemId);
  706. + stm.setInt(4, count);
  707. + stm.setInt(5, 0);
  708. + stm.setString(6, "INVENTORY");
  709. + stm.setInt(7, 0);
  710. + stm.setInt(8, 0);
  711. + stm.setInt(9, 0);
  712. + stm.setInt(10, 0);
  713. + stm.setInt(11, -1);
  714. + stm.setInt(12, 0);
  715. +
  716. + stm.execute();
  717. + }
  718. +
  719. + rset.close();
  720. + stm.close();
  721. + }
  722. + catch (Exception e)
  723. + {
  724. + e.printStackTrace();
  725. + }
  726. + finally
  727. + {
  728. + try
  729. + {
  730. + if (con != null)
  731. + con.close();
  732. + }
  733. + catch (Exception e)
  734. + {
  735. + e.printStackTrace();
  736. + }
  737. + }
  738. + }
  739. +
  740. + private void showAuction(L2PcInstance player, int page, String search)
  741. + {
  742. + boolean src = !search.equals("*null*");
  743. +
  744. + HashMap<Integer, ArrayList<AuctionItem>> items = new HashMap<>();
  745. + int curr = 1;
  746. + int counter = 0;
  747. +
  748. + ArrayList<AuctionItem> temp = new ArrayList<>();
  749. + for (AuctionItem item : AuctionTable.getInstance().getItems())
  750. + {
  751. + if (item.getOwnerId() != player.getObjectId() && (!src || (src && ItemTable.getInstance().getTemplate(item.getItemId()).getName().contains(search))))
  752. + {
  753. + temp.add(item);
  754. +
  755. + counter++;
  756. +
  757. + if (counter == 10)
  758. + {
  759. + items.put(curr, temp);
  760. + temp = new ArrayList<>();
  761. + curr++;
  762. + counter = 0;
  763. + }
  764. + }
  765. + }
  766. + items.put(curr, temp);
  767. +
  768. + if (!items.containsKey(page))
  769. + {
  770. + showChatWindow(player);
  771. + player.sendMessage("Invalid page. Please try again.");
  772. + return;
  773. + }
  774. +
  775. + String html = "<html><title>Auction Shop</title><body><center><br1>";
  776. + html += "<multiedit var=srch width=150 height=20><br1>";
  777. + html += "<button value=\"Search\" action=\"bypass -h npc_"+getObjectId()+"_auction 1 - $srch\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\">";
  778. + html += "<br><table width=310 bgcolor=000000 border=1>";
  779. + html += "<tr><td>Item</td><td>Cost</td><td></td></tr>";
  780. + for (AuctionItem item : items.get(page))
  781. + {
  782. + html += "<tr>";
  783. + html += "<td><img src=\""+IconTable.getInstance().getIcon(item.getItemId())+"\" width=32 height=32 align=center></td>";
  784. + html += "<td>Item: "+(item.getEnchant() > 0 ? "+"+item.getEnchant()+" "+ItemTable.getInstance().getTemplate(item.getItemId()).getName()+" - "+item.getCount() : ItemTable.getInstance().getTemplate(item.getItemId()).getName()+" - "+item.getCount());
  785. + html += "<br1>Cost: "+item.getCostCount()+" "+ItemTable.getInstance().getTemplate(item.getCostId()).getName();
  786. + html += "</td>";
  787. + html += "<td fixwidth=71><button value=\"Buy\" action=\"bypass -h npc_"+getObjectId()+"_buy "+item.getAuctionId()+"\" width=70 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\">";
  788. + html += "</td></tr>";
  789. + }
  790. + html += "</table><br><br>";
  791. +
  792. + html += "Page: "+page;
  793. + html += "<br1>";
  794. +
  795. + if (items.keySet().size() > 1)
  796. + {
  797. + if (page > 1)
  798. + html += "<a action=\"bypass -h npc_"+getObjectId()+"_auction "+(page-1)+" - "+search+"\"><- Prev</a>";
  799. +
  800. + if (items.keySet().size() > page)
  801. + html += "<a action=\"bypass -h npc_"+getObjectId()+"_auction "+(page+1)+" - "+search+"\">Next -></a>";
  802. + }
  803. +
  804. + html += "</center></body></html>";
  805. +
  806. + NpcHtmlMessage htm = new NpcHtmlMessage(getObjectId());
  807. + htm.setHtml(html);
  808. + player.sendPacket(htm);
  809. + }
  810. +
  811. + @Override
  812. + public String getHtmlPath(int npcId, int val)
  813. + {
  814. + String pom = "";
  815. + if (val == 0)
  816. + pom = "" + npcId;
  817. + else
  818. + pom = npcId + "-" + val;
  819. +
  820. + return "data/html/l2spike/auction/" + pom + ".htm";
  821. + }
  822. +}
  823. Index: data/html/l2spike/auction/65529.htm
  824. ===================================================================
  825. --- data/html/l2spike/auction/65529.htm (revision 0)
  826. +++ data/html/l2spike/auction/65529.htm (revision 0)
  827. @@ -0,0 +1,25 @@
  828. +<html>
  829. +<title>
  830. +Auction Shop
  831. +</title>
  832. +<body>
  833. +<center>
  834. +<img src="l2spike.npclogo" width=256 height=95>
  835. +<br><img src="l2spike.splitter" width=256 height=8 align=center>
  836. +<br>
  837. +Welcome to L2Spike auction shop!
  838. +<br>
  839. +<table width=230 bgcolor="000000">
  840. + <tr>
  841. + <td align=center>
  842. + <button value="Shop" action="bypass -h npc_%objectId%_auction 1 - *null*" width=204 height=20 back="sek.cbui81" fore="sek.cbui82">
  843. + <button value="Add item" action="bypass -h npc_%objectId%_addpanel 1" width=204 height=20 back="sek.cbui81" fore="sek.cbui82">
  844. + <button value="My items" action="bypass -h npc_%objectId%_myitems 1" width=204 height=20 back="sek.cbui81" fore="sek.cbui82">
  845. + </td>
  846. + </tr>
  847. +</table>
  848. +<br>
  849. +<img src="l2spike.splitter" width=256 height=8 align=center>
  850. +</center>
  851. +</body>
  852. +</html>
  853. \ No newline at end of file
  854. Index: sql/auction_table.sql
  855. ===================================================================
  856. --- sql/auction_table.sql (revision 0)
  857. +++ sql/auction_table.sql (revision 0)
  858. @@ -0,0 +1,10 @@
  859. +CREATE TABLE IF NOT EXISTS `auction_table` (
  860. + `auctionid` INT UNSIGNED NOT NULL DEFAULT 0,
  861. + `ownerid` INT UNSIGNED NOT NULL DEFAULT 0,
  862. + `itemid` INT UNSIGNED NOT NULL DEFAULT 0,
  863. + `count` INT UNSIGNED NOT NULL DEFAULT 0,
  864. + `enchant` INT UNSIGNED NOT NULL DEFAULT 0,
  865. + `costid` INT UNSIGNED NOT NULL DEFAULT 0,
  866. + `costcount` INT UNSIGNED NOT NULL DEFAULT 0,
  867. + PRIMARY KEY (auctionid)
  868. +);
  869. Index: tools/database_installer.bat
  870. ===================================================================
  871. --- tools/database_installer.bat (revision 17)
  872. +++ tools/database_installer.bat (working copy)
  873. @@ -104,6 +104,7 @@
  874. %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/topic.sql
  875. %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/character_schemes.sql
  876. %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/bots.sql
  877. +%mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/auction_table.sql
  878.  
  879. echo Done.
  880. echo.
  881. Index: tools/database_installer.sh
  882. ===================================================================
  883. --- tools/database_installer.sh (revision 17)
  884. +++ tools/database_installer.sh (working copy)
  885. @@ -124,6 +124,7 @@
  886. $MYG < ../sql/topic.sql &> /dev/null
  887. $MYG < ../sql/character_schemes.sql &> /dev/null
  888. $MYG < ../sql/bots.sql &> /dev/null
  889. +$MYG < ../sql/auction_table.sql &> /dev/null
  890. echo ""
  891. echo "Was fast, isn't it ?"
  892. }
  893. Index: tools/full_install.sql
  894. ===================================================================
  895. --- tools/full_install.sql (revision 17)
  896. +++ tools/full_install.sql (working copy)
  897. @@ -45,4 +45,5 @@
  898. DROP TABLE IF EXISTS siege_clans;
  899. DROP TABLE IF EXISTS topic;
  900. DROP TABLE IF EXISTS character_schemes;
  901. -DROP TABLE IF EXISTS bots;
  902. \ No newline at end of file
  903. +DROP TABLE IF EXISTS bots;
  904. +DROP TABLE IF EXISTS auction_table;
  905. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement