Guest User

AuctionHouseManager01.java

a guest
Mar 16th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 82.71 KB | None | 0 0
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.model;
  16.  
  17. import java.sql.Connection;
  18. import java.sql.PreparedStatement;
  19. import java.sql.ResultSet;
  20. import java.text.DateFormat;
  21. import java.text.DecimalFormat;
  22. import java.util.ArrayList;
  23. import java.util.Collections;
  24. import java.util.Comparator;
  25. import java.util.Date;
  26. import java.util.HashMap;
  27. import java.util.Iterator;
  28. import java.util.List;
  29. import java.util.Locale;
  30. import java.util.Map;
  31. import java.util.Map.Entry;
  32. import java.util.StringTokenizer;
  33. import java.util.TreeMap;
  34. import java.util.logging.Logger;
  35.  
  36. import net.sf.l2j.Config;
  37. import net.sf.l2j.L2DatabaseFactory;
  38. import net.sf.l2j.gameserver.ThreadPoolManager;
  39. import net.sf.l2j.gameserver.cache.HtmCache;
  40. import net.sf.l2j.gameserver.datatables.CharNameTable;
  41. import net.sf.l2j.gameserver.instancemanager.MailManager;
  42. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  43. import net.sf.l2j.gameserver.model.entity.Message;
  44. import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
  45. import net.sf.l2j.gameserver.model.item.instance.ItemInstance.ItemLocation;
  46. import net.sf.l2j.gameserver.model.item.type.CrystalType;
  47. import net.sf.l2j.gameserver.model.itemcontainer.AuctionHouseItem;
  48. import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  49. import net.sf.l2j.gameserver.model.itemcontainer.ItemContainer;
  50. import net.sf.l2j.gameserver.model.itemcontainer.Mail;
  51. import net.sf.l2j.gameserver.network.SystemMessageId;
  52. import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
  53. import net.sf.l2j.gameserver.network.serverpackets.ItemList;
  54. import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  55. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  56. import net.sf.l2j.gameserver.templates.StatsSet;
  57. import net.sf.l2j.gameserver.util.Util;
  58.  
  59. public class AuctionHouseManager01
  60. {
  61. protected static final Logger _log = Logger.getLogger(AuctionHouseManager01.class.getName());
  62.  
  63. private static final DecimalFormat DECIMAL_FORMATTER = new DecimalFormat("#,##0");
  64. private static final DateFormat DATE_FORMATTER = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, new Locale("en", "US"));
  65.  
  66. public static final boolean NORMAL_WEAPON = false;
  67. public static final boolean MAGICAL_WEAPON = true;
  68.  
  69. protected final Map<Integer, AuctionHouseEntrance> _entrancesById = new HashMap<>();
  70. private final Map<String, List<Integer>> _entrancesByCategory = new TreeMap<>();
  71.  
  72. private final Map<Integer, AuctionHouseItem> _containersByCharId = new HashMap<>();
  73.  
  74. protected AuctionHouseManager01()
  75. {
  76. AuctionHouse.generateEntrances(_entrancesById);
  77.  
  78. loadItems();
  79. }
  80.  
  81. private void loadItems()
  82. {
  83. _entrancesByCategory.clear();
  84.  
  85. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  86. PreparedStatement statement = con.prepareStatement("SELECT * FROM auction_house WHERE itemId > 0");
  87. ResultSet res = statement.executeQuery())
  88. {
  89. int itemsCount = 0;
  90. int itemId;
  91. int ownerId;
  92. int count;
  93. int salePrice;
  94. long expirationTime;
  95. AuctionHouseItem container;
  96. AuctionHouse entrance;
  97. while (res.next())
  98. {
  99. itemId = res.getInt("itemId");
  100. ownerId = res.getInt("ownerId");
  101. count = res.getInt("count");
  102. salePrice = res.getInt("sale_price");
  103. expirationTime = res.getLong("expiration_time");
  104.  
  105. if (!_containersByCharId.containsKey(ownerId))
  106. {
  107. container = new AuctionHouseItem(ownerId);
  108. container.restore();
  109. _containersByCharId.put(ownerId, container);
  110. }
  111.  
  112. final ItemInstance item = (ItemInstance) L2World.getInstance().findObject(itemId);
  113. if (item == null)
  114. {
  115. _log.severe(getClass().getSimpleName() + ": The item (" + itemId + ") doesnt exist in the auction. It has another location");
  116. continue;
  117. }
  118.  
  119. entrance = AuctionHouse.getEntranceIdFromItem(item);
  120. _entrancesById.get(entrance.getTopId()).addItem(new AuctionHouseEntranceItem(entrance.getTopId(), ownerId, item, count, salePrice, expirationTime));
  121. itemsCount++;
  122. }
  123.  
  124. _log.info(getClass().getSimpleName() + ": Loaded " + itemsCount + " items on sale in the Auction House");
  125. }
  126. catch (Exception e)
  127. {
  128. _log.severe(getClass().getSimpleName() + ": An error was generated while loading auction items on sale from DB:" + e);
  129. e.printStackTrace();
  130. }
  131.  
  132. // Por ultimo recorremos todas las entradas y creamos un array alterno que va a tener como key su categoria, solo para una rapida referencia
  133. for (AuctionHouseEntrance rank : _entrancesById.values())
  134. {
  135. if (!_entrancesByCategory.containsKey(rank.getCategory()))
  136. {
  137. _entrancesByCategory.put(rank.getCategory(), new ArrayList<Integer>());
  138. }
  139.  
  140. _entrancesByCategory.get(rank.getCategory()).add(rank.getTopId());
  141. }
  142. }
  143.  
  144. public AuctionHouseEntrance getEntranceById(int topId)
  145. {
  146. return _entrancesById.get(topId);
  147. }
  148.  
  149. public Map<Integer, AuctionHouseEntrance> getAllEntrances()
  150. {
  151. return _entrancesById;
  152. }
  153.  
  154. public Map<String, List<Integer>> getEntranceByCategory()
  155. {
  156. return _entrancesByCategory;
  157. }
  158.  
  159. public String processBypass(L2PcInstance activeChar, String command)
  160. {
  161. if (command.equals("_bbsgetfav"))
  162. {
  163. try
  164. {
  165. return makeServerAuctionsHtm(activeChar, -1, null);
  166. }
  167. catch (Exception e)
  168. {
  169. }
  170. }
  171. else if (command.startsWith("_bbsgetfav;server;"))
  172. {
  173. try
  174. {
  175. StringTokenizer st = new StringTokenizer(command, ";");
  176. st.nextToken();
  177. st.nextToken();
  178. final int idTop = Integer.parseInt(st.nextToken());
  179. final StatsSet set = new StatsSet();
  180.  
  181. String token;
  182. while (st.hasMoreTokens())
  183. {
  184. token = st.nextToken();
  185. if (token.startsWith("page"))
  186. {
  187. set.set("page", token.substring(4));
  188. }
  189. else if (token.startsWith("rank"))
  190. {
  191. set.set("rank", token.substring(5).trim());
  192. }
  193. else if (token.startsWith("category"))
  194. {
  195. set.set("category", token.substring(8).trim());
  196. }
  197. else if (token.startsWith("search "))
  198. {
  199. set.set("search", token.substring(7).trim().toLowerCase());
  200. }
  201. else if (token.startsWith("selectedItemId"))
  202. {
  203. set.set("selectedItemId", token.substring(14));
  204. }
  205. else if (token.startsWith("order"))
  206. {
  207. set.set("order", token.substring(5));
  208. }
  209. }
  210.  
  211. return makeServerAuctionsHtm(activeChar, idTop, set);
  212. }
  213. catch (Exception e)
  214. {
  215. return makeServerAuctionsHtm(activeChar, -1, null);
  216. }
  217. }
  218. else if (command.startsWith("_bbsgetfav;my"))
  219. {
  220. try
  221. {
  222. StringTokenizer st = new StringTokenizer(command, ";");
  223. st.nextToken();
  224. st.nextToken();
  225. final StatsSet set = new StatsSet();
  226. long temp;
  227.  
  228. String token;
  229. while (st.hasMoreTokens())
  230. {
  231. token = st.nextToken();
  232. if (token.startsWith("itemId"))
  233. {
  234. set.set("itemId", token.substring(6));
  235. }
  236. else if (token.startsWith("page"))
  237. {
  238. set.set("page", token.substring(4));
  239. }
  240. else if (token.startsWith("selectedAuction"))
  241. {
  242. set.set("selectedAuction", token.substring(15));
  243. }
  244. else if (token.startsWith("apply"))
  245. {
  246. set.set("apply", true);
  247. }
  248. else if (token.startsWith("create"))
  249. {
  250. set.set("create", true);
  251. }
  252. else if (token.startsWith("cancelConfirm"))
  253. {
  254. set.set("cancelConfirm", token.substring(13));
  255. }
  256. else if (token.startsWith("cancel"))
  257. {
  258. set.set("cancel", token.substring(6));
  259. }
  260. else if (token.startsWith("quantity"))
  261. {
  262. // Si viene vacio, es porque no es stackable, por lo que su cantidad es 1
  263. temp = Integer.parseInt(token.substring(9).trim());
  264. set.set("quantity", temp);
  265. if (temp > 1000000)
  266. {
  267. set.set("quantity", 1000000);
  268. }
  269. else if (temp < 1)
  270. {
  271. set.set("quantity", 1);
  272. }
  273. }
  274. else if (token.startsWith("saleprice"))
  275. {
  276. temp = Long.parseLong(token.substring(10).trim());
  277. set.set("saleprice", temp);
  278. if (temp > 10000000000l)
  279. {
  280. set.set("saleprice", 10000000000l);
  281. }
  282. else if (temp < 1)
  283. {
  284. set.set("saleprice", 1);
  285. }
  286. }
  287. else if (token.startsWith("duration"))
  288. {
  289. temp = Integer.parseInt(token.substring(9, 10).trim());
  290. set.set("duration", Integer.parseInt(token.substring(9, 10).trim()));
  291. if (temp < 1)
  292. {
  293. set.set("duration", 1);
  294. }
  295. else if (temp > 9)
  296. {
  297. set.set("duration", 9);
  298. }
  299. }
  300. }
  301.  
  302. return makeMyAuctionsHtm(activeChar, set);
  303. }
  304. catch (Exception e)
  305. {
  306. return makeMyAuctionsHtm(activeChar, null);
  307. }
  308. }
  309. else if (command.startsWith("_bbsgetfav;purchase;"))
  310. {
  311. try
  312. {
  313. StringTokenizer st = new StringTokenizer(command, ";");
  314. st.nextToken();
  315. st.nextToken();
  316. final int idTop = Integer.parseInt(st.nextToken());
  317. final StatsSet set = new StatsSet();
  318.  
  319. try
  320. {
  321. String token;
  322. while (st.hasMoreTokens())
  323. {
  324. token = st.nextToken();
  325. if (token.startsWith("page"))
  326. {
  327. set.set("page", token.substring(4));
  328. }
  329. else if (token.startsWith("rank"))
  330. {
  331. set.set("rank", token.substring(5).trim());
  332. }
  333. else if (token.startsWith("category"))
  334. {
  335. set.set("category", token.substring(8).trim());
  336. }
  337. else if (token.startsWith("search "))
  338. {
  339. set.set("search", token.substring(7).trim().toLowerCase());
  340. }
  341. else if (token.startsWith("selectedItemId"))
  342. {
  343. set.set("selectedItemId", token.substring(14));
  344. }
  345. else if (token.startsWith("order"))
  346. {
  347. set.set("order", token.substring(5));
  348. }
  349. else if (token.startsWith("apply"))
  350. {
  351. set.set("apply", true);
  352. }
  353. else if (token.startsWith("confirm"))
  354. {
  355. set.set("confirm", true);
  356. }
  357. else if (token.startsWith("purchaseCount"))
  358. {
  359. try
  360. {
  361. set.set("purchaseCount", token.substring(14).trim());
  362. }
  363. catch (Exception e)
  364. {
  365. // Aun con error lo seteamos igual, no quiero perder la pantalla porque escribio algo mal
  366. set.set("purchaseCount", 1);
  367. }
  368. }
  369. }
  370.  
  371. return makePurchaseHtm(activeChar, idTop, set);
  372. }
  373. catch (Exception e)
  374. {
  375. // El segundo try, va a capturar los errores del purchase en si. Si falla tratamos de volver a la pantalla de donde estaba antes, lo mejor posible
  376. return makeServerAuctionsHtm(activeChar, idTop, set);
  377. }
  378. }
  379. catch (Exception e)
  380. {
  381. return makeServerAuctionsHtm(activeChar, -1, null);
  382. }
  383. }
  384.  
  385. return null;
  386. }
  387.  
  388. public String makeServerAuctionsHtm(L2PcInstance activeChar, int topId, StatsSet set)
  389. {
  390. String content = HtmCache.getInstance().getHtm("data/html/CommunityBoard/auction_house_server.htm");
  391. if (content == null)
  392. {
  393. return "<html><body><br><br><center>404 :File Not foud: 'data/html/CommunityBoard/auction_house_server.htm' </center></body></html>";
  394. }
  395.  
  396. final int MAX_ENTRANCES_PER_PAGE = 9;
  397. final AuctionHouseEntrance top = getEntranceById(topId);
  398. final String category = (set != null ? set.getString("category", null) : null);
  399. final String rankSelected = (set != null ? set.getString("rank", "All") : "All");
  400. String searchSelected = (set != null ? set.getString("search", null) : null);
  401. if (searchSelected != null)
  402. {
  403. searchSelected = searchSelected.toLowerCase();
  404. }
  405. final String order = (set != null ? set.getString("order", "NameAsc") : "NameAsc");
  406.  
  407. final List<AuctionHouseEntranceItem> items = new ArrayList<>();
  408. if (top != null)
  409. {
  410. final long currentTime = System.currentTimeMillis();
  411. final Iterator<AuctionHouseEntranceItem> it = top.getItems().iterator();
  412. AuctionHouseEntranceItem item;
  413. while (it.hasNext())
  414. {
  415. item = it.next();
  416. if (item == null)
  417. {
  418. continue;
  419. }
  420.  
  421. if (item.isRemoved())
  422. {
  423. continue;
  424. }
  425.  
  426. if (item.getEndTime() < currentTime)
  427. {
  428. returnItemToOwner(item);
  429. continue;
  430. }
  431.  
  432. switch (rankSelected)
  433. {
  434. case "NG":
  435. if (item.getItemInstance().getItem().getCrystalType() != CrystalType.NONE)
  436. {
  437. continue;
  438. }
  439. break;
  440. case "D":
  441. if (item.getItemInstance().getItem().getCrystalType() != CrystalType.D)
  442. {
  443. continue;
  444. }
  445. break;
  446. case "C":
  447. if (item.getItemInstance().getItem().getCrystalType() != CrystalType.C)
  448. {
  449. continue;
  450. }
  451. break;
  452. case "B":
  453. if (item.getItemInstance().getItem().getCrystalType() != CrystalType.B)
  454. {
  455. continue;
  456. }
  457. break;
  458. case "A":
  459. if (item.getItemInstance().getItem().getCrystalType() != CrystalType.A)
  460. {
  461. continue;
  462. }
  463. break;
  464. case "S":
  465. if (item.getItemInstance().getItem().getCrystalType() != CrystalType.S)
  466. {
  467. continue;
  468. }
  469. break;
  470. }
  471.  
  472. if ((searchSelected != null) && !item.getItemInstance().getItem().getName().toLowerCase().contains(searchSelected))
  473. {
  474. continue;
  475. }
  476.  
  477. items.add(item);
  478. }
  479. }
  480. else if ((category != null) && _entrancesByCategory.containsKey(category))
  481. {
  482. final long currentTime = System.currentTimeMillis();
  483. AuctionHouseEntranceItem item;
  484. for (int allTopId : _entrancesByCategory.get(category))
  485. {
  486. final Iterator<AuctionHouseEntranceItem> it = getEntranceById(allTopId).getItems().iterator();
  487.  
  488. while (it.hasNext())
  489. {
  490. item = it.next();
  491. if (item == null)
  492. {
  493. continue;
  494. }
  495.  
  496. if (item.isRemoved())
  497. {
  498. continue;
  499. }
  500.  
  501. if (item.getEndTime() < currentTime)
  502. {
  503. returnItemToOwner(item);
  504. continue;
  505. }
  506.  
  507. switch (rankSelected)
  508. {
  509. case "NG":
  510. if (item.getItemInstance().getItem().getCrystalType() != CrystalType.NONE)
  511. {
  512. continue;
  513. }
  514. break;
  515. case "D":
  516. if (item.getItemInstance().getItem().getCrystalType() != CrystalType.D)
  517. {
  518. continue;
  519. }
  520. break;
  521. case "C":
  522. if (item.getItemInstance().getItem().getCrystalType() != CrystalType.C)
  523. {
  524. continue;
  525. }
  526. break;
  527. case "B":
  528. if (item.getItemInstance().getItem().getCrystalType() != CrystalType.B)
  529. {
  530. continue;
  531. }
  532. break;
  533. case "A":
  534. if (item.getItemInstance().getItem().getCrystalType() != CrystalType.A)
  535. {
  536. continue;
  537. }
  538. break;
  539. case "S":
  540. if (item.getItemInstance().getItem().getCrystalType() != CrystalType.S)
  541. {
  542. continue;
  543. }
  544. break;
  545. }
  546.  
  547. if ((searchSelected != null) && !item.getItemInstance().getItem().getName().toLowerCase().contains(searchSelected))
  548. {
  549. continue;
  550. }
  551.  
  552. items.add(item);
  553. }
  554. }
  555. }
  556.  
  557. if ((order != null) && !items.isEmpty())
  558. {
  559. switch (order)
  560. {
  561. case "NameAsc":
  562. Collections.sort(items, NAME_ASC_COMPARATOR);
  563. break;
  564. case "NameDesc":
  565. Collections.sort(items, NAME_DESC_COMPARATOR);
  566. break;
  567. case "CountAsc":
  568. Collections.sort(items, COUNT_ASC_COMPARATOR);
  569. break;
  570. case "CountDesc":
  571. Collections.sort(items, COUNT_DESC_COMPARATOR);
  572. break;
  573. case "PriceAsc":
  574. Collections.sort(items, PRICE_ASC_COMPARATOR);
  575. break;
  576. case "PriceDesc":
  577. Collections.sort(items, PRICE_DESC_COMPARATOR);
  578. break;
  579. }
  580. }
  581.  
  582. final int entrancesSize = items.size();
  583. final int maxPageN = (entrancesSize - 1) / MAX_ENTRANCES_PER_PAGE;
  584. final StringBuilder valores = new StringBuilder();
  585. boolean changeColor = false;
  586.  
  587. content = content.replace("%itemCount%", "<font color=8a7c62>(" + entrancesSize + ")</font>");
  588.  
  589. final int ITEMS_TABLE_WIDTH = 565;
  590. final int currentPage = (set != null ? Math.min(maxPageN, set.getInteger("page", 0)) : 0);
  591. final int selectedItemId = (set != null ? set.getInteger("selectedItemId", -1) : -1);
  592. for (int i = currentPage * MAX_ENTRANCES_PER_PAGE; i < ((currentPage * MAX_ENTRANCES_PER_PAGE) + MAX_ENTRANCES_PER_PAGE); i++)
  593. {
  594. if (entrancesSize > i)
  595. {
  596. if (items.get(i).getCharId() == activeChar.getObjectId())
  597. {
  598. valores.append("<table width=" + ITEMS_TABLE_WIDTH + " height=36 cellspacing=-1 bgcolor=" + (changeColor ? "171612" : "23221e") + ">");
  599. valores.append("<tr>");
  600. valores.append("<td width=42 valign=top><img src=" + items.get(i).getItemInstance().getItem().getIcon(i) + " width=32 height=32></td>");
  601. }
  602. else if (items.get(i).getObjectId() == selectedItemId)
  603. {
  604. valores.append("<table width=" + ITEMS_TABLE_WIDTH + " height=36 cellspacing=-1 bgcolor=999a45>");
  605. valores.append("<tr>");
  606. valores.append("<td width=42 valign=top><img src=" + items.get(i).getItemInstance().getItem().getIcon(i) + " width=32 height=32></td>");
  607. }
  608. else
  609. {
  610. valores.append("<table width=" + ITEMS_TABLE_WIDTH + " height=36 cellspacing=-1 bgcolor=" + (changeColor ? "171612" : "23221e") + ">");
  611. valores.append("<tr>");
  612. valores.append("<td width=42 valign=top><button value=\"\" width=32 height=32 action=\"bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + (order != null ? ";order" + order : "") + ";selectedItemId" + items.get(i).getObjectId() + ";page" + currentPage + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "") + "\" fore=" + items.get(i).getItemInstance().getItem().getIcon(i) + " back=" + items.get(i).getItemInstance().getItem().getIcon(i) + "></td>");
  613. }
  614.  
  615. valores.append("<td fixwidth=250>" + getCompleteItemName(items.get(i).getItemInstance(), true, false) + "</td>");
  616. valores.append("<td width=60 align=center>" + items.get(i).getItemInstance().getItem().getCrystalName() + "</td>");
  617. valores.append("<td width=100 align=center>" + DECIMAL_FORMATTER.format(items.get(i).getQuantity()).replace(".", ",") + "</td>");
  618. valores.append("<td width=130 align=center><font color=777978>" + DECIMAL_FORMATTER.format(items.get(i).getPrice()).replace(".", ",") + "</font></td>");
  619. valores.append("<td width=10 align=right></td>");
  620. valores.append("</tr>");
  621. valores.append("</table>");
  622. changeColor = !changeColor;
  623. }
  624. else
  625. {
  626. valores.append("<table width=" + ITEMS_TABLE_WIDTH + " height=36 cellspacing=-1 bgcolor=" + (changeColor ? "171612" : "23221e") + ">");
  627. valores.append("<tr>");
  628. valores.append("<td width=42><font color=" + (changeColor ? "151412" : "242320") + ">.</font></td>");
  629. /**
  630. * valores.append("<td width=250></td>"); valores.append("<td width=60></td>"); valores.append("<td width=100></td>"); valores.append("<td width=130></td>"); valores.append("<td width=10></td>");
  631. */
  632. valores.append("<td width=550></td>");
  633.  
  634. valores.append("</tr>");
  635. valores.append("</table>");
  636. changeColor = !changeColor;
  637. }
  638. }
  639.  
  640. final int initialPage = Math.max(0, currentPage - 10);
  641. final int finalPage = Math.min(maxPageN, currentPage + 10);
  642. valores.append("<table width=" + ITEMS_TABLE_WIDTH + " height=38 cellspacing=-1 bgcolor=" + (changeColor ? "171612" : "23221e") + ">");
  643. valores.append("<tr>");
  644. valores.append("<td width=" + ((ITEMS_TABLE_WIDTH - ((finalPage - initialPage) + ((finalPage - initialPage) * 30) + 40)) / 2) + " height=16></td>");
  645. valores.append("<td width=20></td>");
  646. for (int i = initialPage; i <= finalPage; i++)
  647. {
  648. if (i != initialPage)
  649. {
  650. valores.append("<td width=1></td>");
  651. }
  652.  
  653. valores.append("<td width=30></td>");
  654. }
  655. valores.append("<td width=20></td>");
  656. valores.append("<td width=" + ((ITEMS_TABLE_WIDTH - ((finalPage - initialPage) + ((finalPage - initialPage) * 30) + 40)) / 2) + "></td>");
  657. valores.append("</tr>");
  658. valores.append("<tr>");
  659. if (currentPage > 0)
  660. {
  661. valores.append("<td fixheight=10 align=right><button value=\"\" width=16 height=16 action=\"bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + (order != null ? ";order" + order : "") + ";page0;rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "") + "\" fore=L2UI_CH3.shortcut_prev_down back=L2UI_CH3.shortcut_prev></td>");
  662. valores.append("<td align=right><button value=\"\" width=16 height=16 action=\"bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + (order != null ? ";order" + order : "") + ";page" + (currentPage - 1) + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "") + "\" fore=L2UI_CH3.shortcut_prev_down back=L2UI_CH3.shortcut_prev></td>");
  663. }
  664. else
  665. {
  666. valores.append("<td fixheight=10 align=right><button value=\"\" width=16 height=16 action=\"\" fore=L2UI_CH3.shortcut_prev back=L2UI_CH3.shortcut_prev></td>");
  667. valores.append("<td align=right><button value=\"\" width=16 height=16 action=\"\" fore=L2UI_CH3.shortcut_prev back=L2UI_CH3.shortcut_prev></td>");
  668. }
  669. for (int i = initialPage; i <= finalPage; i++)
  670. {
  671. if (i != initialPage)
  672. {
  673. valores.append("<td align=center valign=middle><img src=L2UI.SquareGray width=1 height=12></td>");
  674. }
  675.  
  676. if (i == currentPage)
  677. {
  678. valores.append("<td align=center valign=middle><font color=bab43e>" + (i + 1) + "</font></td>");
  679. }
  680. else
  681. {
  682. valores.append("<td align=center valign=middle>" + (i + 1) + "</td>");
  683. }
  684. }
  685. if (currentPage < maxPageN)
  686. {
  687. valores.append("<td><button value=\"\" width=16 height=16 action=\"bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + (order != null ? ";order" + order : "") + ";page" + (currentPage + 1) + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "") + "\" fore=L2UI_CH3.shortcut_next_down back=L2UI_CH3.shortcut_next_down></td>");
  688. valores.append("<td><button value=\"\" width=16 height=16 action=\"bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + (order != null ? ";order" + order : "") + ";page" + maxPageN + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "") + "\" fore=L2UI_CH3.shortcut_next_down back=L2UI_CH3.shortcut_next_down></td>");
  689. }
  690. else
  691. {
  692. valores.append("<td><button value=\"\" width=16 height=16 action=\"\" fore=L2UI_CH3.shortcut_next back=L2UI_CH3.shortcut_next></td>");
  693. valores.append("<td><button value=\"\" width=16 height=16 action=\"\" fore=L2UI_CH3.shortcut_next back=L2UI_CH3.shortcut_next></td>");
  694. }
  695. valores.append("</tr>");
  696. valores.append("</table>");
  697.  
  698. final String purchaseButtonName;
  699. final String purchaseButtonAction;
  700. if (selectedItemId >= 0)
  701. {
  702. purchaseButtonName = "Purchase";
  703. purchaseButtonAction = "bypass _bbsgetfav;purchase;" + topId + ";selectedItemId" + selectedItemId + (category != null ? ";category" + category : "") + (order != null ? ";order" + order : "") + ";page" + (currentPage + 1) + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "");
  704. }
  705. else
  706. {
  707. purchaseButtonName = "Purchase";
  708. purchaseButtonAction = "";
  709. }
  710.  
  711. final StringBuilder categorias = new StringBuilder();
  712. int freeCategoryHeight = 382;
  713.  
  714. for (Entry<String, List<Integer>> tops : getEntranceByCategory().entrySet())
  715. {
  716. String catName = tops.getKey();
  717. switch (catName)
  718. {
  719. case "Accesory":
  720. catName += " ";
  721. break;
  722. case "Armor":
  723. catName += " ";
  724. break;
  725. case "Etc":
  726. catName += " ";
  727. break;
  728. case "Supplies":
  729. catName += " ";
  730. break;
  731. case "Weapon":
  732. catName += " ";
  733. break;
  734. }
  735.  
  736. if (((top != null) && tops.getKey().equalsIgnoreCase(top.getCategory())) || ((category != null) && tops.getKey().equalsIgnoreCase(category)))
  737. {
  738. categorias.append("<tr>");
  739. categorias.append("<td fixwidth=10 fixheight=10 valign=top><button value=\"\" width=16 height=16 action=\"bypass _bbsgetfav;server;-1\" fore=L2UI_CH3.QuestWndMinusBtn back=L2UI_CH3.QuestWndMinusBtn></td>");
  740. if ((category != null) && category.equalsIgnoreCase(tops.getKey()))
  741. {
  742. categorias.append("<td width=140 valign=top><button value=\"" + catName + "\" width=60 height=13 action=\"\" fore=\"\" back=\"\"></td>");
  743. }
  744. else
  745. {
  746. categorias.append("<td width=140 valign=top><button value=\"" + catName + "\" width=60 height=13 action=\"bypass _bbsgetfav;server;-1;category" + tops.getKey() + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "") + "\" fore=\"\" back=\"\"></td>");
  747. }
  748. categorias.append("</tr>");
  749.  
  750. freeCategoryHeight -= 38;
  751.  
  752. for (Integer rankId : tops.getValue())
  753. {
  754. categorias.append("<tr>");
  755. categorias.append("<td></td>");
  756. categorias.append("<td>");
  757. categorias.append("<table width=140 cellspacing=0 bgcolor=" + (topId == rankId ? "726c42" : (changeColor ? "171612" : "23221e")) + ">");
  758. categorias.append("<tr>");
  759. if (topId == rankId)
  760. {
  761. categorias.append("<td fixheight=13><button value=\"" + getEntranceById(rankId).getTopName() + "\" width=140 height=13 action=\"\" fore=\"\" back=\"\"></td>");
  762. }
  763. else
  764. {
  765. categorias.append("<td fixheight=13><button value=\"" + getEntranceById(rankId).getTopName() + "\" width=140 height=13 action=\"bypass _bbsgetfav;server;" + rankId + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "") + "\" fore=\"\" back=\"\"></td>");
  766. }
  767. categorias.append("</tr>");
  768. categorias.append("<tr>");
  769. categorias.append("<td fixheight=2></td>");
  770. categorias.append("</tr>");
  771. categorias.append("</table>");
  772. categorias.append("</td>");
  773. categorias.append("</tr>");
  774. changeColor = !changeColor;
  775.  
  776. freeCategoryHeight -= 15;
  777. }
  778.  
  779. categorias.append("<tr>");
  780. categorias.append("<td fixheight=2></td>");
  781. categorias.append("<td></td>");
  782. categorias.append("</tr>");
  783.  
  784. freeCategoryHeight -= 2;
  785. }
  786. else
  787. {
  788. categorias.append("<tr>");
  789. categorias.append("<td fixwidth=10 fixheight=10 valign=top><button value=\"\" width=16 height=16 action=\"bypass _bbsgetfav;server;-1;category" + tops.getKey() + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "") + "\" fore=L2UI_CH3.QuestWndPlusBtn back=L2UI_CH3.QuestWndPlusBtn></td>");
  790. if ((category != null) && category.equalsIgnoreCase(tops.getKey()))
  791. {
  792. categorias.append("<td width=140 valign=top><button value=\"" + catName + "\" width=60 height=13 action=\"\" fore=\"\" back=\"\"></td>");
  793. }
  794. else
  795. {
  796. categorias.append("<td width=140 valign=top><button value=\"" + catName + "\" width=60 height=13 action=\"bypass _bbsgetfav;server;-1;category" + tops.getKey() + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "") + "\" fore=\"\" back=\"\"></td>");
  797. }
  798. categorias.append("</tr>");
  799.  
  800. if ((top == null) && (category == null))
  801. {
  802. freeCategoryHeight -= 19;
  803. }
  804. else
  805. {
  806. freeCategoryHeight -= 16;
  807. }
  808. }
  809. }
  810.  
  811. categorias.append("<tr>");
  812. categorias.append("<td height=" + Math.min(382 - (getEntranceByCategory().size() * 19) - 2, freeCategoryHeight) + "></td>");
  813. categorias.append("<td></td>");
  814. categorias.append("</tr>");
  815.  
  816. final String searchButtonAction = "bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + ";rank " + rankSelected + " ;search $search";
  817.  
  818. final String applyButtonAction = "bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + ";rank $rank " + (searchSelected != null ? ";search " + searchSelected : "");
  819.  
  820. final String refreshButtonAction = "bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + (order != null ? ";order" + order : "") + ";page" + currentPage + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "");
  821.  
  822. final String itemOrderAction = "bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + ((order == null) || order.equalsIgnoreCase("NameDesc") ? ";orderNameAsc" : ";orderNameDesc") + ";page" + currentPage + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "");
  823. final String rankOrderAction = "bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + ((order == null) || order.equalsIgnoreCase("RankDesc") ? ";orderRankAsc" : ";orderRankDesc") + ";page" + currentPage + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "");
  824. final String countOrderAction = "bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + ((order == null) || order.equalsIgnoreCase("CountDesc") ? ";orderCountAsc" : ";orderCountDesc") + ";page" + currentPage + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "");
  825. final String priceOrderAction = "bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + ((order == null) || order.equalsIgnoreCase("PriceDesc") ? ";orderPriceAsc" : ";orderPriceDesc") + ";page" + currentPage + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "");
  826.  
  827. content = content.replace("%selectedGrade%", rankSelected);
  828. content = content.replace("%categorias%", categorias.toString());
  829. content = content.replace("%tablas%", valores.toString());
  830. content = content.replace("%adenaCount%", "\"" + DECIMAL_FORMATTER.format(activeChar.getInventory().getAdena()).replace(".", ",") + "\"");
  831. content = content.replace("%applyButtonAction%", applyButtonAction);
  832. content = content.replace("%searchButtonAction%", searchButtonAction);
  833. content = content.replace("%refreshButtonAction%", refreshButtonAction);
  834. content = content.replace("%purchaseButtonName%", purchaseButtonName);
  835. content = content.replace("%purchaseButtonAction%", purchaseButtonAction);
  836. content = content.replace("%itemOrderAction%", itemOrderAction);
  837. content = content.replace("%rankOrderAction%", rankOrderAction);
  838. content = content.replace("%countOrderAction%", countOrderAction);
  839. content = content.replace("%priceOrderAction%", priceOrderAction);
  840.  
  841. // Eliminamos tabs y espacios para hacer mas chico el html
  842. content = content.replace("\t", "");
  843. content = content.replace("\n", "");
  844. return content;
  845. }
  846.  
  847. public String makePurchaseHtm(L2PcInstance activeChar, int topId, StatsSet set) throws Exception
  848. {
  849. String content = HtmCache.getInstance().getHtm("data/html/CommunityBoard/auction_house_purchase.htm");
  850. if (content == null)
  851. {
  852. return "<html><body><br><br><center>404 :File Not foud: 'data/html/CommunityBoard/auction_house_purchase.htm' </center></body></html>";
  853. }
  854.  
  855. if (set == null)
  856. {
  857. throw new Exception();
  858. }
  859.  
  860. final int selectedItemId = set.getInteger("selectedItemId", -1);
  861. if (selectedItemId < 1)
  862. {
  863. throw new Exception();
  864. }
  865.  
  866. final String category = set.getString("category", null);
  867. AuctionHouseEntranceItem item = null;
  868.  
  869. if ((category != null) && _entrancesByCategory.containsKey(category))
  870. {
  871. boolean isFound = false;
  872. for (int allTopId : _entrancesByCategory.get(category))
  873. {
  874. for (AuctionHouseEntranceItem items : getEntranceById(allTopId).getItems())
  875. {
  876. if (items.getObjectId() == selectedItemId)
  877. {
  878. item = items;
  879. isFound = true;
  880. break;
  881. }
  882. }
  883. if (isFound)
  884. {
  885. break;
  886. }
  887. }
  888. }
  889. else
  890. {
  891. final AuctionHouseEntrance top = getEntranceById(topId);
  892. if (top == null)
  893. {
  894. throw new Exception();
  895. }
  896.  
  897. for (AuctionHouseEntranceItem items : top.getItems())
  898. {
  899. if (items.getObjectId() == selectedItemId)
  900. {
  901. item = items;
  902. break;
  903. }
  904. }
  905. }
  906.  
  907. if ((item == null) || (item.getQuantity() < 1) || (item.getItemInstance() == null) || item.isRemoved())
  908. {
  909. throw new Exception();
  910. }
  911.  
  912. final String rankSelected = set.getString("rank", "All");
  913. final String searchSelected = set.getString("search", null);
  914. final String order = set.getString("order", null);
  915. final int page = set.getInteger("page", 0);
  916. final boolean isStackable = item.getItemInstance().isStackable();
  917. final int purchaseCount = Math.min(item.getQuantity(), set.getInteger("purchaseCount", 1));
  918.  
  919. // Si viene un confirm, significa que esta tratando de comprar el item de un action, por lo que ya si se puede o no comprar, lo hacemos y mostramos el html de donde partio esto
  920. if (set.getBool("confirm", false))
  921. {
  922. purchaseItem(order, activeChar, set, item, purchaseCount);
  923. return makeServerAuctionsHtm(activeChar, topId, set);
  924. }
  925.  
  926. final String purchaseButtonName;
  927. final String purchaseButtonAction;
  928. final String cancelButtonName;
  929. final String cancelButtonAction;
  930. if (set.getBool("apply", false))
  931. {
  932. purchaseButtonName = "Confirm Purchase";
  933. purchaseButtonAction = "bypass _bbsgetfav;purchase;" + topId + (category != null ? ";category" + category : "") + (order != null ? ";order" + order : "") + ";confirm;selectedItemId" + selectedItemId + ";purchaseCount " + purchaseCount + ";page" + page + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "");
  934. cancelButtonName = "Edit Purchase";
  935. cancelButtonAction = "bypass _bbsgetfav;purchase;" + topId + (category != null ? ";category" + category : "") + (order != null ? ";order" + order : "") + ";selectedItemId" + selectedItemId + ";page" + page + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "");
  936. }
  937. else
  938. {
  939. purchaseButtonName = "Apply";
  940. if (!isStackable || (item.getQuantity() == 1))
  941. {
  942. purchaseButtonAction = "bypass _bbsgetfav;purchase;" + topId + (category != null ? ";category" + category : "") + (order != null ? ";order" + order : "") + ";apply;selectedItemId" + selectedItemId + ";purchaseCount 1;page" + page + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "");
  943. }
  944. else
  945. {
  946. purchaseButtonAction = "bypass _bbsgetfav;purchase;" + topId + (category != null ? ";category" + category : "") + (order != null ? ";order" + order : "") + ";apply;selectedItemId" + selectedItemId + ";purchaseCount $quantity ;page" + page + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "");
  947. }
  948. cancelButtonName = "Cancel Purchase";
  949. cancelButtonAction = "bypass _bbsgetfav;server;" + topId + (category != null ? ";category" + category : "") + ";selectedItemId" + selectedItemId + ";page" + page + ";rank " + rankSelected + (searchSelected != null ? ";search " + searchSelected : "");
  950. }
  951.  
  952. final StringBuilder itemSelected = new StringBuilder();
  953. itemSelected.append("<tr>");
  954. itemSelected.append("<td width=35 valign=middle><img src=" + item.getItemInstance().getItem().getIcon(purchaseCount) + " width=32 height=32></td>");
  955. itemSelected.append("<td width=5></td>");
  956. itemSelected.append("<td fixwidth=225 align=center>" + getCompleteItemName(item.getItemInstance(), true, false) + (item.getQuantity() > 1 ? " X" + item.getQuantity() : "") + "</td>");
  957. itemSelected.append("</tr>");
  958.  
  959. final String quantity;
  960. final String salePrice;
  961. final String totalPrice;
  962.  
  963. if (set.getBool("apply", false))
  964. {
  965. quantity = "<button value=\"" + DECIMAL_FORMATTER.format(purchaseCount).replace(".", ",") + "\" width=160 height=20 action=\"\" fore=L2UI_CT1.Windows_DF_TooltipBG back=L2UI_CT1.Windows_DF_TooltipBG>";
  966. salePrice = DECIMAL_FORMATTER.format(item.getPrice()).replace(".", ",");
  967. totalPrice = DECIMAL_FORMATTER.format(purchaseCount * item.getPrice()).replace(".", ",");
  968. }
  969. else
  970. {
  971. if (!isStackable || (item.getQuantity() == 1))
  972. {
  973. quantity = "<button value=\"1\" width=160 height=20 action=\"\" fore=L2UI_CT1.Windows_DF_TooltipBG back=L2UI_CT1.Windows_DF_TooltipBG>";
  974. }
  975. else
  976. {
  977. quantity = "<edit var=quantity width=160 height=10>";
  978. }
  979. salePrice = DECIMAL_FORMATTER.format(item.getPrice()).replace(".", ",");
  980. totalPrice = DECIMAL_FORMATTER.format(item.getPrice()).replace(".", ",");
  981. }
  982.  
  983. final String itemName = getCompleteItemName(item.getItemInstance(), true, true);
  984. final String sellerName = CharNameTable.getInstance().getNameById(item.getCharId());
  985.  
  986. final String itemGrade;
  987. switch (item.getItemInstance().getItem().getCrystalType())
  988. {
  989. case D:
  990. itemGrade = "<td fixwidth=16 fixheight=16><img src=symbol.grade_d width=16 height=16></td>";
  991. break;
  992. case C:
  993. itemGrade = "<td fixwidth=16 fixheight=16><img src=symbol.grade_c width=16 height=16></td>";
  994. break;
  995. case B:
  996. itemGrade = "<td fixwidth=16 fixheight=16><img src=symbol.grade_b width=16 height=16></td>";
  997. break;
  998. case A:
  999. itemGrade = "<td fixwidth=16 fixheight=16><img src=symbol.grade_a width=16 height=16></td>";
  1000. break;
  1001. case S:
  1002. itemGrade = "<td fixwidth=16 fixheight=16><img src=symbol.grade_s width=16 height=16></td>";
  1003. break;
  1004. default:
  1005. itemGrade = "<td></td>";
  1006. break;
  1007. }
  1008.  
  1009. final String itemStats;
  1010. if (item.getItemInstance().isWeapon())
  1011. {
  1012. itemStats = "<tr><td height=25 align=center><font color=888a89>P. Atk:</font> <font color=a09675>" + (int) item.getItemInstance().getItem().getValueFromStatFunc(activeChar, item.getItemInstance(), "pAtk", "0x08") + "</font></td></tr>" + "<tr><td height=25 align=center><font color=888a89>M. Atk:</font> <font color=a09675>" + (int) item.getItemInstance().getItem().getValueFromStatFunc(activeChar, item.getItemInstance(), "mAtk", "0x08") + "</font></td></tr>";
  1013. }
  1014. else if (item.getItemInstance().getItem().isJewel())
  1015. {
  1016. itemStats = "<tr><td height=25 align=center><font color=888a89>M. Def:</font> <font color=a09675>" + (int) item.getItemInstance().getItem().getValueFromStatFunc(activeChar, item.getItemInstance(), "mDef", "0x10") + "</font></td></tr>";
  1017. }
  1018. else if (item.getItemInstance().isArmor())
  1019. {
  1020. itemStats = "<tr><td height=25 align=center><font color=888a89>P. Def:</font> <font color=a09675>" + (int) item.getItemInstance().getItem().getValueFromStatFunc(activeChar, item.getItemInstance(), "pDef", "0x10") + "</font></td></tr>";
  1021. }
  1022. else
  1023. {
  1024. itemStats = "";
  1025. }
  1026.  
  1027. content = content.replace("%itemSelected%", itemSelected.toString());
  1028. content = content.replace("%adenaCount%", DECIMAL_FORMATTER.format(activeChar.getInventory().getAdena()).replace(".", ","));
  1029. content = content.replace("%cancelButtonName%", cancelButtonName);
  1030. content = content.replace("%cancelButtonAction%", cancelButtonAction);
  1031. content = content.replace("%purchaseButtonName%", purchaseButtonName);
  1032. content = content.replace("%purchaseButtonAction%", purchaseButtonAction);
  1033. content = content.replace("%quantity%", quantity);
  1034. content = content.replace("%salePrice%", salePrice);
  1035. content = content.replace("%totalPrice%", totalPrice);
  1036. content = content.replace("%itemName%", itemName);
  1037. content = content.replace("%itemGrade%", itemGrade);
  1038. content = content.replace("%sellerName%", (sellerName != null ? sellerName : ""));
  1039. content = content.replace("%itemStats%", itemStats);
  1040.  
  1041. // Eliminamos tabs y espacios para hacer mas chico el html
  1042. content = content.replace("\t", "");
  1043. content = content.replace("\n", "");
  1044. return content;
  1045. }
  1046.  
  1047. public String makeMyAuctionsHtm(L2PcInstance activeChar, StatsSet set)
  1048. {
  1049. String content = HtmCache.getInstance().getHtm("data/html/CommunityBoard/auction_house_my.htm");
  1050. if (content == null)
  1051. {
  1052. return "<html><body><br><br><center>404 :File Not foud: 'data/html/CommunityBoard/auction_house_my.htm' </center></body></html>";
  1053. }
  1054.  
  1055. // Si viene un create, significa que esta tratando de poner en auction un item. Hacemos todos los chequeos
  1056. if ((set != null) && set.getBool("create", false))
  1057. {
  1058. createNewAuction(content, activeChar, set);
  1059. }
  1060.  
  1061. // Si viene un cancel, significa que esta tratando de cancelar un auction activo del pj
  1062. else if ((set != null) && (set.getInteger("cancelConfirm", -1) >= 0))
  1063. {
  1064. cancelAuction(content, activeChar, set);
  1065. }
  1066.  
  1067. final int MAX_ITEMS_PER_LINE = 5;
  1068. final StringBuilder valores = new StringBuilder();
  1069. boolean changeColor = false;
  1070.  
  1071. final List<AuctionHouseEntranceItem> items = new ArrayList<>();
  1072. for (AuctionHouseEntrance entrance : getAllEntrances().values())
  1073. {
  1074. for (AuctionHouseEntranceItem item : entrance.getItems())
  1075. {
  1076. if ((item != null) && (item.getCharId() == activeChar.getObjectId()) && !item.isRemoved())
  1077. {
  1078. items.add(item);
  1079. }
  1080. }
  1081. }
  1082.  
  1083. content = content.replace("%itemCount%", "<font color=8a7c62>(" + items.size() + "/10)</font>");
  1084.  
  1085. // Llenamos la lista de items que el pj esta vendiendo. Si o si debe haber 10 celdas, aunque sea vacias
  1086. final int selectedAuction = (set != null ? set.getInteger("selectedAuction", -1) : -1);
  1087. for (int i = 0; i < 10; i++)
  1088. {
  1089. if (items.size() > i)
  1090. {
  1091. if (items.get(i).getObjectId() == selectedAuction)
  1092. {
  1093. valores.append("<table height=36 cellspacing=-1 bgcolor=999a45>");
  1094. valores.append("<tr>");
  1095. valores.append("<td width=38 valign=middle><img src=" + items.get(i).getItemInstance().getItem().getIcon(i) + " width=32 height=32></td>");
  1096. }
  1097. else
  1098. {
  1099. valores.append("<table height=36 valign=middle cellspacing=-1 bgcolor=" + (changeColor ? "171612" : "23221e") + ">");
  1100. valores.append("<tr>");
  1101. valores.append("<td width=38 valign=middle><button value=\"\" width=32 height=32 action=\"bypass _bbsgetfav;my;selectedAuction" + items.get(i).getObjectId() + "\" fore=" + items.get(i).getItemInstance().getItem().getIcon(i) + " back=" + items.get(i).getItemInstance().getItem().getIcon(i) + "></td>");
  1102. }
  1103. valores.append("<td fixwidth=192>" + getCompleteItemName(items.get(i).getItemInstance(), false, true) + "</td>");
  1104. valores.append("<td width=60 align=center>" + items.get(i).getItemInstance().getItem().getCrystalName() + "</td>");
  1105. valores.append("<td width=80 align=center>" + DECIMAL_FORMATTER.format(items.get(i).getQuantity()).replace(".", ",") + "</td>");
  1106. valores.append("<td width=100 align=center>" + DECIMAL_FORMATTER.format(items.get(i).getPrice()).replace(".", ",") + "</td>");
  1107. valores.append("<td width=80 align=center>" + items.get(i).getRemainingTimeString() + "</td>");
  1108. valores.append("</tr>");
  1109. valores.append("</table>");
  1110. changeColor = !changeColor;
  1111. }
  1112. else
  1113. {
  1114. valores.append("<table height=36 cellspacing=-1 bgcolor=" + (changeColor ? "171612" : "23221e") + ">");
  1115. valores.append("<tr>");
  1116. valores.append("<td width=38><font color=" + (changeColor ? "151412" : "242320") + ">.</font></td>");
  1117. valores.append("<td width=192></td>");
  1118. valores.append("<td width=60></td>");
  1119. valores.append("<td width=80></td>");
  1120. valores.append("<td width=100></td>");
  1121. valores.append("<td width=80></td>");
  1122. valores.append("</tr>");
  1123. valores.append("</table>");
  1124. changeColor = !changeColor;
  1125. }
  1126. }
  1127.  
  1128. final String cancelButtonName;
  1129. final String cancelButtonAction;
  1130. if (selectedAuction >= 0)
  1131. {
  1132. if ((set != null) && (set.getInteger("cancel", -1) >= 0))
  1133. {
  1134. cancelButtonName = "Confirm Cancel";
  1135. cancelButtonAction = "bypass _bbsgetfav;my;cancelConfirm" + selectedAuction;
  1136. }
  1137. else
  1138. {
  1139. cancelButtonName = "Cancel Auction";
  1140. cancelButtonAction = "bypass _bbsgetfav;my;selectedAuction" + selectedAuction + ";cancel" + selectedAuction;
  1141. }
  1142. }
  1143. else
  1144. {
  1145. cancelButtonName = "Cancel Auction";
  1146. cancelButtonAction = "";
  1147. }
  1148.  
  1149. final StringBuilder inventario = new StringBuilder();
  1150.  
  1151. final List<ItemInstance> sellList = new ArrayList<>();
  1152. for (ItemInstance item : activeChar.getInventory().getItems())
  1153. {
  1154. if (!item.isEquipped() && item.isSellable() // Vendible
  1155. && item.isTradable() // Tradeable
  1156. && (item.getItemId() != Inventory.ADENA_ID // No adena
  1157. ) && ((activeChar.getPet() == null) || (item.getObjectId() != activeChar.getPet().getControlItemId()))) // Pet is summoned and not the item that summoned the pet
  1158. {
  1159. sellList.add(item);
  1160. }
  1161. }
  1162.  
  1163. final int maxPage = (int) Math.ceil((double) sellList.size() / MAX_ITEMS_PER_LINE) - 3;
  1164. int selectedQuantity = (set != null ? set.getInteger("quantity", 0) : 0);
  1165. int selectedItemId = (set != null ? set.getInteger("itemId", 0) : 0);
  1166. long selectedSalePrice = (set != null ? set.getLong("saleprice", 0) : 0);
  1167. int currentPage = (set != null ? Math.min(maxPage, set.getInteger("page", -1)) : -1); // La ultima pagina deberia verse en la 3ra fila, asi no se muestran filas vacias
  1168. int selectedItemIndex = 0;
  1169. String itemName = "";
  1170. String itemIcon = "<img src=\"\" width=32 height=32>";
  1171. long itemCount = 1;
  1172. boolean isStackable = false;
  1173.  
  1174. if ((currentPage > -1) && ((currentPage * MAX_ITEMS_PER_LINE) <= sellList.size()) && (selectedItemId < 1))
  1175. {
  1176. selectedItemIndex = currentPage * MAX_ITEMS_PER_LINE;
  1177. itemIcon = "<img src=" + sellList.get(selectedItemIndex).getItem().getIcon(selectedItemIndex) + " width=32 height=32>";
  1178. itemName = getCompleteItemName(sellList.get(selectedItemIndex), true, false);
  1179. itemCount = sellList.get(selectedItemIndex).getCount();
  1180. isStackable = sellList.get(selectedItemIndex).isStackable();
  1181. selectedItemId = sellList.get(selectedItemIndex).getObjectId();
  1182.  
  1183. if (selectedQuantity > itemCount)
  1184. {
  1185. selectedQuantity = (int) itemCount;
  1186. }
  1187.  
  1188. if (selectedSalePrice < (sellList.get(selectedItemIndex).getReferencePrice() / 2))
  1189. {
  1190. selectedSalePrice = sellList.get(selectedItemIndex).getReferencePrice() / 2;
  1191. }
  1192. }
  1193. else
  1194. {
  1195. for (int i = 0; i < sellList.size(); i++)
  1196. {
  1197. if ((selectedItemId == 0) || (sellList.get(i).getObjectId() == selectedItemId))
  1198. {
  1199. selectedItemIndex = i;
  1200. itemIcon = "<img src=" + sellList.get(i).getItem().getIcon(i) + " width=32 height=32>";
  1201. itemName = getCompleteItemName(sellList.get(i), true, false);
  1202. itemCount = sellList.get(i).getCount();
  1203. isStackable = sellList.get(i).isStackable();
  1204. if ((currentPage < 0) || ((currentPage * MAX_ITEMS_PER_LINE) > sellList.size()))
  1205. {
  1206. currentPage = Math.max(0, Math.min(maxPage, i / MAX_ITEMS_PER_LINE));
  1207. }
  1208. selectedItemId = sellList.get(i).getObjectId();
  1209.  
  1210. if (selectedQuantity > itemCount)
  1211. {
  1212. selectedQuantity = (int) itemCount;
  1213. }
  1214.  
  1215. if (selectedSalePrice < (sellList.get(i).getReferencePrice() / 2))
  1216. {
  1217. selectedSalePrice = sellList.get(i).getReferencePrice() / 2;
  1218. }
  1219. break;
  1220. }
  1221. }
  1222. }
  1223. if (currentPage < 0)
  1224. {
  1225. currentPage = 0;
  1226. }
  1227.  
  1228. final int startIndex = currentPage * MAX_ITEMS_PER_LINE;
  1229. for (int i = startIndex; i < sellList.size(); i++)
  1230. {
  1231. if ((i - startIndex) >= (MAX_ITEMS_PER_LINE * 3))
  1232. {
  1233. break;
  1234. }
  1235.  
  1236. if ((i % MAX_ITEMS_PER_LINE) == 0)
  1237. {
  1238. inventario.append("<tr>");
  1239. }
  1240.  
  1241. inventario.append("<td fixwidth=42 height=42 valign=top>");
  1242. if (i == selectedItemIndex)
  1243. {
  1244. inventario.append("<table width=42 height=42 cellpadding=5 cellspacing=0 background=BranchSys.br_icon_limited><tr><td align=center valign=middle>");
  1245. inventario.append("<button value=\"\" width=32 height=32 action=\"\" fore=" + sellList.get(i).getItem().getIcon(i) + " back=" + sellList.get(i).getItem().getIcon(i) + ">");
  1246. inventario.append("</td></tr></table>");
  1247. }
  1248. else
  1249. {
  1250. inventario.append("<table width=42 height=42 cellpadding=5 cellspacing=0><tr><td align=center valign=middle>");
  1251. inventario.append("<button value=\"\" width=32 height=32 action=\"bypass _bbsgetfav;my;itemId" + sellList.get(i).getObjectId() + ";page" + currentPage + "\" fore=" + sellList.get(i).getItem().getIcon(i) + " back=" + sellList.get(i).getItem().getIcon(i) + ">");
  1252. inventario.append("</td></tr></table>");
  1253. }
  1254. inventario.append("</td>");
  1255.  
  1256. if ((i + 1) == sellList.size())
  1257. {
  1258. for (int z = 0; z < Math.round(MAX_ITEMS_PER_LINE - (i % MAX_ITEMS_PER_LINE) - 1); z++)
  1259. {
  1260. // Como los items van con tablas, si hay menos de 5 items uso la tabla asi el ancho del inventario no se achica, luego uso tds directamente por temas de tamanho de html
  1261. if (sellList.size() < MAX_ITEMS_PER_LINE)
  1262. {
  1263. inventario.append("<td fixwidth=42 height=42 valign=top>");
  1264. inventario.append("<table width=42 height=42 cellpadding=5 cellspacing=0><tr><td align=center valign=middle>");
  1265. inventario.append("<button value=\"\" width=32 height=32 action=\"\" fore=\"\" back=\"\">");
  1266. inventario.append("</td></tr></table>");
  1267. inventario.append("</td>");
  1268. }
  1269. else
  1270. {
  1271. inventario.append("<td fixwidth=42 height=42 valign=top><button value=\"\" width=32 height=32 action=\"\" fore=\"\" back=\"\"></td>");
  1272. }
  1273. }
  1274. }
  1275.  
  1276. if ((((i + 1) % MAX_ITEMS_PER_LINE) == 0) || ((i - startIndex) >= (MAX_ITEMS_PER_LINE * 3)))
  1277. {
  1278. inventario.append("</tr>");
  1279. }
  1280.  
  1281. if ((i + 1) == sellList.size())
  1282. {
  1283. if (sellList.size() <= MAX_ITEMS_PER_LINE)
  1284. {
  1285. inventario.append("<tr>");
  1286. inventario.append("<td fixwidth=42 height=42 valign=top></td>");
  1287. inventario.append("</tr>");
  1288. inventario.append("<tr>");
  1289. inventario.append("<td fixwidth=42 height=42 valign=top></td>");
  1290. inventario.append("</tr>");
  1291. }
  1292. else if (sellList.size() <= (MAX_ITEMS_PER_LINE * 2))
  1293. {
  1294. inventario.append("<tr>");
  1295. inventario.append("<td fixwidth=42 height=42 valign=top></td>");
  1296. inventario.append("</tr>");
  1297. }
  1298. }
  1299. }
  1300.  
  1301. final StringBuilder flechasInventario = new StringBuilder();
  1302. flechasInventario.append("<table cellpadding=-2 cellspacing=3>");
  1303. flechasInventario.append("<tr>");
  1304. flechasInventario.append("<td width=4></td>");
  1305. if (currentPage < 1)
  1306. {
  1307. flechasInventario.append("<td fixheight=16><button value=\"\" width=16 height=16 action=\"\" fore=L2UI_CH3.joypad_shortcut back=L2UI_CH3.joypad_shortcut></td>");
  1308. }
  1309. else
  1310. {
  1311. flechasInventario.append("<td fixheight=16><button value=\"\" width=16 height=16 action=\"bypass _bbsgetfav;my;page0" + (selectedItemId > 0 ? ";itemId" + selectedItemId : "") + "\" fore=L2UI_CH3.joypad_shortcut_over back=L2UI_CH3.joypad_shortcut_over></td>");
  1312. }
  1313. flechasInventario.append("</tr>");
  1314. flechasInventario.append("<tr>");
  1315. flechasInventario.append("<td></td>");
  1316. if (currentPage < 1)
  1317. {
  1318. flechasInventario.append("<td fixheight=16><button value=\"\" width=16 height=16 action=\"\" fore=L2UI_CH3.shortcut_nextv back=L2UI_CH3.shortcut_nextv></td>");
  1319. }
  1320. else
  1321. {
  1322. flechasInventario.append("<td fixheight=16><button value=\"\" width=16 height=16 action=\"bypass _bbsgetfav;my;page" + (currentPage - 1) + (selectedItemId > 0 ? ";itemId" + selectedItemId : "") + "\" fore=L2UI_CH3.shortcut_nextv_over back=L2UI_CH3.shortcut_nextv_over></td>");
  1323. }
  1324. flechasInventario.append("</tr>");
  1325. flechasInventario.append("<tr>");
  1326. flechasInventario.append("<td></td>");
  1327. flechasInventario.append("<td height=58></td>");
  1328. flechasInventario.append("</tr>");
  1329. flechasInventario.append("<tr>");
  1330. flechasInventario.append("<td></td>");
  1331. if (currentPage >= maxPage)
  1332. {
  1333. flechasInventario.append("<td fixheight=16><button value=\"\" width=16 height=16 action=\"\" fore=L2UI_CH3.shortcut_prevv back=L2UI_CH3.shortcut_prevv></td>");
  1334. }
  1335. else
  1336. {
  1337. flechasInventario.append("<td fixheight=16><button value=\"\" width=16 height=16 action=\"bypass _bbsgetfav;my;page" + (currentPage + 1) + (selectedItemId > 0 ? ";itemId" + selectedItemId : "") + "\" fore=L2UI_CH3.shortcut_prevv_over back=L2UI_CH3.shortcut_prevv_over></td>");
  1338. }
  1339. flechasInventario.append("</tr>");
  1340. flechasInventario.append("<tr>");
  1341. flechasInventario.append("<td></td>");
  1342. if (currentPage >= maxPage)
  1343. {
  1344. flechasInventario.append("<td fixheight=16><button value=\"\" width=16 height=16 action=\"\" fore=L2UI_CH3.joypad_shortcut back=L2UI_CH3.joypad_shortcut></td>");
  1345. }
  1346. else
  1347. {
  1348. flechasInventario.append("<td fixheight=16><button value=\"\" width=16 height=16 action=\"bypass _bbsgetfav;my;page" + maxPage + (selectedItemId > 0 ? ";itemId" + selectedItemId : "") + "\" fore=L2UI_CH3.joypad_shortcut_over back=L2UI_CH3.joypad_shortcut_over></td>");
  1349. }
  1350. flechasInventario.append("</tr>");
  1351. flechasInventario.append("</table>");
  1352.  
  1353. final StringBuilder itemSelected = new StringBuilder();
  1354. itemSelected.append("<tr>");
  1355. itemSelected.append("<td><table width=60 height=48 cellpadding=7 cellspacing=0 background=L2UI_ct1.ShortcutWnd_DF_Select><tr><td align=center valign=middle>" + itemIcon + "</td></tr></table></td>");
  1356. itemSelected.append("<td width=5></td>");
  1357. itemSelected.append("<td fixwidth=120>" + itemName + (itemCount > 1 ? " X" + itemCount : "") + "</td>");
  1358. itemSelected.append("</tr>");
  1359.  
  1360. final String auctionButtonName;
  1361. final String auctionButtonAction;
  1362. final String quantity;
  1363. final String salePrice;
  1364. final String duration;
  1365. final String totalPrice;
  1366. final String saleFee;
  1367.  
  1368. if ((selectedItemId > 0) && (set != null) && set.getBool("apply", false))
  1369. {
  1370. auctionButtonName = "Auction Item";
  1371. auctionButtonAction = "bypass _bbsgetfav;my;itemId" + selectedItemId + ";create;quantity " + selectedQuantity + " ;saleprice " + selectedSalePrice + " ;duration " + set.getLong("duration", 1);
  1372.  
  1373. quantity = "background=L2UI_CT1.Windows_DF_TooltipBG><button value=\"" + DECIMAL_FORMATTER.format(selectedQuantity).replace(".", ",") + "\" width=120 height=20 action=\"\" fore=\"\" back=\"\">";
  1374. salePrice = "background=L2UI_CT1.Windows_DF_TooltipBG><button value=\"" + DECIMAL_FORMATTER.format(selectedSalePrice).replace(".", ",") + "\" width=120 height=20 action=\"\" fore=\"\" back=\"\">";
  1375. duration = "background=L2UI_CT1.Windows_DF_TooltipBG><button value=\"" + set.getInteger("duration", 1) + " day(s)\" width=120 height=20 action=\"\" fore=\"\" back=\"\">";
  1376. totalPrice = DECIMAL_FORMATTER.format(selectedQuantity * selectedSalePrice).replace(".", ",");
  1377. // El precio que se cobra es igual a: quantity * salePrice * cantidadDias * 0.5%. Lo minimo son 10k
  1378. saleFee = DECIMAL_FORMATTER.format(calculateSaleFee(activeChar, selectedQuantity, selectedSalePrice, set.getInteger("duration", 1))).replace(".", ",");
  1379. }
  1380. else if (selectedItemId > 0)
  1381. {
  1382. auctionButtonName = "Apply";
  1383.  
  1384. if (!isStackable || (itemCount == 1))
  1385. {
  1386. auctionButtonAction = "bypass _bbsgetfav;my;itemId" + selectedItemId + ";apply;quantity 1 ;saleprice $saleprice ;duration $duration";
  1387. quantity = "background=L2UI_CT1.Windows_DF_TooltipBG><button value=\"1\" width=120 height=20 action=\"\" fore=L2UI_CT1.Windows_DF_TooltipBG back=L2UI_CT1.Windows_DF_TooltipBG>";
  1388. }
  1389. else
  1390. {
  1391. auctionButtonAction = "bypass _bbsgetfav;my;itemId" + selectedItemId + ";apply;quantity $quantity ;saleprice $saleprice ;duration $duration";
  1392. quantity = "><edit var=quantity width=120 height=10>";
  1393. }
  1394. salePrice = "><edit var=saleprice width=120 height=10>";
  1395. duration = "><combobox width=120 height=10 var=duration list=\"1 day(s);2 day(s);3 day(s);4 day(s);5 day(s);6 day(s);7 day(s);8 day(s);9 day(s)\">";
  1396. totalPrice = "0";
  1397. saleFee = "10,000";
  1398. }
  1399. else
  1400. {
  1401. auctionButtonName = "Auction Item";
  1402. auctionButtonAction = "";
  1403. quantity = "><edit var=quantity width=120 height=10>";
  1404. salePrice = "><edit var=saleprice width=120 height=10>";
  1405. duration = "><combobox width=120 height=10 var=duration list=\"1 day(s);2 day(s);3 day(s);4 day(s);5 day(s);6 day(s);7 day(s);8 day(s);9 day(s)\">";
  1406. totalPrice = "0";
  1407. saleFee = "10,000";
  1408. }
  1409.  
  1410. content = content.replace("%inventario%", inventario.toString());
  1411. content = content.replace("%inventarioFlechas%", flechasInventario.toString());
  1412. content = content.replace("%itemSelected%", itemSelected.toString());
  1413. content = content.replace("%tablas%", valores.toString());
  1414. content = content.replace("%adenaCount%", DECIMAL_FORMATTER.format(activeChar.getInventory().getAdena()).replace(".", ","));
  1415. content = content.replace("%auctionButtonName%", auctionButtonName);
  1416. content = content.replace("%auctionButtonAction%", auctionButtonAction);
  1417. content = content.replace("%cancelButtonName%", cancelButtonName);
  1418. content = content.replace("%cancelButtonAction%", cancelButtonAction);
  1419. content = content.replace("%quantity%", quantity);
  1420. content = content.replace("%salePrice%", salePrice);
  1421. content = content.replace("%duration%", duration);
  1422. content = content.replace("%totalPrice%", totalPrice);
  1423. content = content.replace("%saleFee%", saleFee);
  1424.  
  1425. // Eliminamos tabs y espacios para hacer mas chico el html
  1426. content = content.replace("\t", "");
  1427. content = content.replace("\n", "");
  1428. return content;
  1429. }
  1430.  
  1431. private synchronized void createNewAuction(String command, L2PcInstance activeChar, StatsSet set)
  1432. {
  1433. if (command.startsWith("createAuction"))
  1434. {
  1435. return;
  1436. }
  1437.  
  1438. if (!activeChar.getAccessLevel().allowTransaction())
  1439. {
  1440. activeChar.sendMessage("Transactions are disabled for your Access Level");
  1441. return;
  1442. }
  1443.  
  1444. if (activeChar.getActiveTradeList() != null)
  1445. {
  1446. activeChar.sendMessage("You cant create an auction while having an active exchange");
  1447. return;
  1448. }
  1449.  
  1450. if (activeChar.isInJail())
  1451. {
  1452. activeChar.sendMessage("You cant create an auction while in Jail");
  1453. return;
  1454. }
  1455.  
  1456. if (activeChar.isTeleporting() || activeChar.isCastingNow() || activeChar.isAttackingNow())
  1457. {
  1458. activeChar.sendMessage("You cant create an auction while casting/attacking");
  1459. return;
  1460. }
  1461.  
  1462. // Chequeamos que todas las variables necesarias esten seteadas y sean correctas
  1463. final int itemId = set.getInteger("itemId", 0);
  1464. if (itemId < 1)
  1465. {
  1466. return;
  1467. }
  1468.  
  1469. final int quantity = set.getInteger("quantity", 0);
  1470. if ((quantity < 1) || (quantity > 1000000))
  1471. {
  1472. activeChar.sendMessage("Wrong Auction Item Quantity");
  1473. return;
  1474. }
  1475.  
  1476. final int salePrice = set.getInteger("saleprice", 0);
  1477. if ((salePrice < 1) || (salePrice > 10000000000l))
  1478. {
  1479. activeChar.sendMessage("Wrong Auction Sale Price");
  1480. return;
  1481. }
  1482.  
  1483. final int duration = set.getInteger("duration", 1);
  1484. if ((duration < 1) || (duration > 9))
  1485. {
  1486. activeChar.sendMessage("Wrong Auction Duration");
  1487. return;
  1488. }
  1489.  
  1490. // Controlamos que tenga la adena necesaria para pagar el auction fee. El precio que se cobra es igual a: quantity * salePrice * cantidadDias * 0.5%. Lo minimo son 10k
  1491. final long saleFee = (long) calculateSaleFee(activeChar, quantity, salePrice, duration);
  1492. if (activeChar.getAdena() < saleFee)
  1493. {
  1494. activeChar.sendMessage("Not enough adena to pay the Auction Fee");
  1495. return;
  1496. }
  1497.  
  1498. final ItemInstance item = activeChar.checkItemManipulation(itemId, quantity);
  1499. if ((item == null) || !item.isSellable() || !item.isTradable() || item.isEquipped())
  1500. {
  1501. activeChar.sendMessage("Not a valid item for Auction");
  1502. return;
  1503. }
  1504.  
  1505. synchronized (_entrancesById)
  1506. {
  1507. int auctionedItemsN = 0;
  1508. for (AuctionHouseEntrance entrance : _entrancesById.values())
  1509. {
  1510. for (AuctionHouseEntranceItem it : entrance.getItems())
  1511. {
  1512. if (it.getObjectId() == item.getObjectId())
  1513. {
  1514. activeChar.sendMessage("This item is already in auction");
  1515. return;
  1516. }
  1517.  
  1518. if (it.getCharId() == activeChar.getObjectId())
  1519. {
  1520. auctionedItemsN++;
  1521.  
  1522. // Los items stackables solo pueden ponerse a vender una vez, porque comparten el objectId ya que se apilan. Por lo que solo puede haber una venta de un stackable
  1523. if (item.isStackable() && (it.getItemInstance().getItemId() == item.getItemId()))
  1524. {
  1525. activeChar.sendMessage("You cannot auction this item because its an stackable item and its already in auction by you");
  1526. activeChar.sendMessage("If you still want to auction this item, you must cancel your sale first");
  1527. return;
  1528. }
  1529. }
  1530. }
  1531. }
  1532.  
  1533. if (auctionedItemsN >= 10)
  1534. {
  1535. activeChar.sendMessage("You can only have 10 auctions maximum at the same time");
  1536. return;
  1537. }
  1538.  
  1539. if (!activeChar.reduceAdena("Auction", (int) saleFee, null, true))
  1540. {
  1541. activeChar.sendMessage("Not enough adena to pay the Auction Fee");
  1542. return;
  1543. }
  1544.  
  1545. final AuctionHouseItem container;
  1546. if (!_containersByCharId.containsKey(activeChar.getObjectId()))
  1547. {
  1548. container = new AuctionHouseItem(activeChar.getObjectId());
  1549. _containersByCharId.put(activeChar.getObjectId(), container);
  1550. }
  1551. else
  1552. {
  1553. container = _containersByCharId.get(activeChar.getObjectId());
  1554. }
  1555.  
  1556. final ItemInstance newItem = activeChar.getInventory().transferItem("AuctionHouse", itemId, quantity, container, activeChar, null);
  1557. if (newItem == null)
  1558. {
  1559. activeChar.sendMessage("An error has ocurred while recieving your item. Please report to a Game Master");
  1560. _log.warning("Error recieving item for auction house of " + activeChar.getName() + " (newitem == null)");
  1561. return;
  1562. }
  1563. newItem.setLocation(container.getBaseLocation());
  1564.  
  1565. final InventoryUpdate playerIU = Config.FORCE_INVENTORY_UPDATE ? null : new InventoryUpdate();
  1566. if (playerIU != null)
  1567. {
  1568. if ((item.getCount() > 0) && (item != newItem))
  1569. {
  1570. playerIU.addModifiedItem(item);
  1571. }
  1572. else
  1573. {
  1574. playerIU.addRemovedItem(item);
  1575. }
  1576. }
  1577.  
  1578. if (playerIU != null)
  1579. {
  1580. activeChar.sendPacket(playerIU);
  1581. }
  1582. else
  1583. {
  1584. activeChar.sendPacket(new ItemList(activeChar, false));
  1585. }
  1586.  
  1587. final StatusUpdate su = new StatusUpdate(activeChar);
  1588. su.addAttribute(StatusUpdate.CUR_LOAD, activeChar.getCurrentLoad());
  1589. activeChar.sendPacket(su);
  1590.  
  1591. addNewAuctionToDB(activeChar, newItem, quantity, salePrice, duration);
  1592. }
  1593. }
  1594.  
  1595. private synchronized void cancelAuction(String command, L2PcInstance activeChar, StatsSet set)
  1596. {
  1597. if (command.startsWith("cancelAuction"))
  1598. {
  1599. return;
  1600. }
  1601.  
  1602. if (!activeChar.getAccessLevel().allowTransaction())
  1603. {
  1604. activeChar.sendMessage("Transactions are disabled for your Access Level");
  1605. return;
  1606. }
  1607.  
  1608. if (activeChar.getActiveTradeList() != null)
  1609. {
  1610. activeChar.sendMessage("You cant cancel an auction while having an active exchange");
  1611. return;
  1612. }
  1613.  
  1614. if (activeChar.isInJail())
  1615. {
  1616. activeChar.sendMessage("You cant cancel an auction while in Jail");
  1617. return;
  1618. }
  1619.  
  1620. if (activeChar.isTeleporting() || activeChar.isCastingNow() || activeChar.isAttackingNow())
  1621. {
  1622. activeChar.sendMessage("You cant cancel an auction while casting/attacking");
  1623. return;
  1624. }
  1625.  
  1626. synchronized (_entrancesById)
  1627. {
  1628. final int cancelObjectId = set.getInteger("cancelConfirm", -1);
  1629. for (AuctionHouseEntrance entrance : _entrancesById.values())
  1630. {
  1631. for (AuctionHouseEntranceItem item : entrance.getItems())
  1632. {
  1633. if (item.getCharId() != activeChar.getObjectId())
  1634. {
  1635. continue;
  1636. }
  1637.  
  1638. if (item.getObjectId() != cancelObjectId)
  1639. {
  1640. continue;
  1641. }
  1642.  
  1643. final ItemContainer container = _containersByCharId.get(activeChar.getObjectId());
  1644. if ((container == null) || (container.getSize() == 0))
  1645. {
  1646. activeChar.sendMessage("You cant cancel this auction. Something is missing");
  1647. return;
  1648. }
  1649.  
  1650. if (item.getItemInstance().getOwnerId() != activeChar.getObjectId())
  1651. {
  1652. Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " tried to get not own item from cancelled attachment!", Config.DEFAULT_PUNISH);
  1653. return;
  1654. }
  1655.  
  1656. if (item.getItemInstance().getLocation() != ItemLocation.AUCTIONH)
  1657. {
  1658. Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " tried to get items not from mail !", Config.DEFAULT_PUNISH);
  1659. return;
  1660. }
  1661.  
  1662. final long weight = item.getItemInstance().getCount() * item.getItemInstance().getItem().getWeight();
  1663. int slots = 0;
  1664. if (!item.getItemInstance().isStackable())
  1665. {
  1666. slots += item.getItemInstance().getCount();
  1667. }
  1668. else if (activeChar.getInventory().getItemByItemId(item.getItemInstance().getItemId()) == null)
  1669. {
  1670. slots++;
  1671. }
  1672.  
  1673. if (!activeChar.getInventory().validateCapacity(slots))
  1674. {
  1675. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SLOTS_FULL));
  1676. return;
  1677. }
  1678.  
  1679. if (!activeChar.getInventory().validateWeight(weight))
  1680. {
  1681. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SLOTS_FULL));
  1682. return;
  1683. }
  1684.  
  1685. final InventoryUpdate playerIU = Config.FORCE_INVENTORY_UPDATE ? null : new InventoryUpdate();
  1686.  
  1687. final long count = item.getItemInstance().getCount();
  1688. final ItemInstance newItem = container.transferItem(container.getName(), item.getObjectId(), (int) count, activeChar.getInventory(), activeChar, null);
  1689. if (newItem == null)
  1690. {
  1691. activeChar.sendMessage("You cant cancel this auction. Something is wrong. Report to a Game Master");
  1692. return;
  1693. }
  1694.  
  1695. if (playerIU != null)
  1696. {
  1697. if (newItem.getCount() > count)
  1698. {
  1699. playerIU.addModifiedItem(newItem);
  1700. }
  1701. else
  1702. {
  1703. playerIU.addNewItem(newItem);
  1704. }
  1705. }
  1706.  
  1707. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.EARNED_ITEM_S1);
  1708. sm.addItemName(item.getItemInstance().getItemId());
  1709. // TODO: Check if this any way to fix it
  1710. // sm.addItemName(count);
  1711. activeChar.sendPacket(sm);
  1712.  
  1713. if (playerIU != null)
  1714. {
  1715. activeChar.sendPacket(playerIU);
  1716. }
  1717. else
  1718. {
  1719. activeChar.sendPacket(new ItemList(activeChar, false));
  1720. }
  1721.  
  1722. final StatusUpdate su = new StatusUpdate(activeChar);
  1723. su.addAttribute(StatusUpdate.CUR_LOAD, activeChar.getCurrentLoad());
  1724. activeChar.sendPacket(su);
  1725.  
  1726. modifyAuctionItemCountToDB(item, -1);
  1727.  
  1728. activeChar.sendMessage("Auction cancelled succesfully");
  1729.  
  1730. set.set("itemId", 0);
  1731. set.set("page", 0);
  1732. return;
  1733. }
  1734. }
  1735. }
  1736.  
  1737. activeChar.sendMessage("The selected auction couldn't be cancelled");
  1738. }
  1739.  
  1740. private synchronized void purchaseItem(String command, L2PcInstance activeChar, StatsSet set, AuctionHouseEntranceItem item, int purchaseCount)
  1741. {
  1742. if (item == null)
  1743. {
  1744. activeChar.sendMessage("The selected auction couldn't be purchased");
  1745. return;
  1746. }
  1747.  
  1748. if (command.startsWith("purchaseItem"))
  1749. {
  1750. return;
  1751. }
  1752.  
  1753. if (!activeChar.getAccessLevel().allowTransaction())
  1754. {
  1755. activeChar.sendMessage("Transactions are disabled for your Access Level");
  1756. return;
  1757. }
  1758.  
  1759. if (activeChar.getActiveTradeList() != null)
  1760. {
  1761. activeChar.sendMessage("You cant purchase an item while having an active exchange");
  1762. return;
  1763. }
  1764.  
  1765. if (activeChar.isInJail())
  1766. {
  1767. activeChar.sendMessage("You cant purchase an item while in Jail");
  1768. return;
  1769. }
  1770.  
  1771. if (activeChar.isTeleporting() || activeChar.isCastingNow() || activeChar.isAttackingNow())
  1772. {
  1773. activeChar.sendMessage("You cant purchase an item while casting/attacking");
  1774. return;
  1775. }
  1776.  
  1777. synchronized (_entrancesById)
  1778. {
  1779. if (item.getCharId() == activeChar.getObjectId())
  1780. {
  1781. activeChar.sendMessage("You cant purchase your own items!");
  1782. return;
  1783. }
  1784.  
  1785. // El item senalado no es el actual. No deberia llegar a esto la verdad
  1786. final int purchaseObjectId = set.getInteger("selectedItemId", -1);
  1787. if (item.getObjectId() != purchaseObjectId)
  1788. {
  1789. activeChar.sendMessage("Invalid item");
  1790. return;
  1791. }
  1792.  
  1793. final ItemContainer container = _containersByCharId.get(item.getCharId());
  1794. if ((container == null) || (container.getSize() == 0))
  1795. {
  1796. activeChar.sendMessage("You cant purchase this item. Something is missing");
  1797. return;
  1798. }
  1799.  
  1800. if (item.getItemInstance().getLocation() != ItemLocation.AUCTIONH)
  1801. {
  1802. Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " tried to get items not from mail !", Config.DEFAULT_PUNISH);
  1803. return;
  1804. }
  1805.  
  1806. if (activeChar.getAdena() < (item.getPrice() * purchaseCount))
  1807. {
  1808. activeChar.sendMessage("Not enough adena to purchase this item");
  1809. return;
  1810. }
  1811.  
  1812. final long weight = purchaseCount * item.getItemInstance().getItem().getWeight();
  1813. int slots = 0;
  1814. if (!item.getItemInstance().isStackable())
  1815. {
  1816. slots += purchaseCount;
  1817. }
  1818. else if (activeChar.getInventory().getItemByItemId(item.getItemInstance().getItemId()) == null)
  1819. {
  1820. slots++;
  1821. }
  1822.  
  1823. if (!activeChar.getInventory().validateCapacity(slots))
  1824. {
  1825. activeChar.sendMessage("You cant purchase this item. You dont have enough slots");
  1826. return;
  1827. }
  1828.  
  1829. if (!activeChar.getInventory().validateWeight(weight))
  1830. {
  1831. activeChar.sendMessage("You cant purchase this item. You dont have enough weight available");
  1832. return;
  1833. }
  1834.  
  1835. if (!activeChar.reduceAdena("AuctionHouse", item.getPrice() * purchaseCount, null, true))
  1836. {
  1837. activeChar.sendMessage("Not enough adena to purchase this item");
  1838. return;
  1839. }
  1840.  
  1841. final InventoryUpdate playerIU = Config.FORCE_INVENTORY_UPDATE ? null : new InventoryUpdate();
  1842. final ItemInstance newItem = container.transferItem(container.getName(), item.getObjectId(), purchaseCount, activeChar.getInventory(), activeChar, null);
  1843. if (newItem == null)
  1844. {
  1845. activeChar.sendMessage("You cant purchase this item. Something is wrong. Report to a Game Master");
  1846. return;
  1847. }
  1848.  
  1849. if (playerIU != null)
  1850. {
  1851. if (newItem.getCount() > purchaseCount)
  1852. {
  1853. playerIU.addModifiedItem(newItem);
  1854. }
  1855. else
  1856. {
  1857. playerIU.addNewItem(newItem);
  1858. }
  1859. }
  1860.  
  1861. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.EARNED_ITEM_S1);
  1862. sm.addItemName(item.getItemInstance().getItemId());
  1863. sm.addItemName(purchaseCount);
  1864. activeChar.sendPacket(sm);
  1865.  
  1866. if (playerIU != null)
  1867. {
  1868. activeChar.sendPacket(playerIU);
  1869. }
  1870. else
  1871. {
  1872. activeChar.sendPacket(new ItemList(activeChar, false));
  1873. }
  1874.  
  1875. final StatusUpdate su = new StatusUpdate(activeChar);
  1876. su.addAttribute(StatusUpdate.CUR_LOAD, activeChar.getCurrentLoad());
  1877. activeChar.sendPacket(su);
  1878.  
  1879. final String message = "The player " + activeChar.getName() + " has bought " + item.getItemInstance().getItem().getName() + "\nQuantity: " + DECIMAL_FORMATTER.format(purchaseCount).replace(".", ",") + "\nTotal: " + DECIMAL_FORMATTER.format(item.getPrice() * purchaseCount).replace(".", ",") + " Adena" + "\nDate: " + DATE_FORMATTER.format(new Date(System.currentTimeMillis())) + "\n\nThanks for using our Auction House system";
  1880. Message msg = new Message(activeChar, item.getCharId(), "Auction House Sell", message, Message.SendBySystem.NONE);
  1881. Mail attachments = msg.createAttachments();
  1882. attachments.addItem("AuctionHouse", Inventory.ADENA_ID, item.getPrice() * purchaseCount, null, null);
  1883. MailManager.getInstance().sendMessage(msg);
  1884.  
  1885. modifyAuctionItemCountToDB(item, item.getQuantity() - purchaseCount);
  1886.  
  1887. activeChar.sendMessage("You have succesfully purchased " + newItem.getItem().getName());
  1888. }
  1889. }
  1890.  
  1891. private synchronized void returnItemToOwner(AuctionHouseEntranceItem item)
  1892. {
  1893. if (item.isRemoved())
  1894. {
  1895. return;
  1896. }
  1897.  
  1898. item.setIsRemoved(true);
  1899.  
  1900. final ItemContainer container = _containersByCharId.get(item.getCharId());
  1901. if ((container == null) || (container.getSize() == 0))
  1902. {
  1903. return;
  1904. }
  1905.  
  1906. if (item.getItemInstance().getLocation() != ItemLocation.AUCTIONH)
  1907. {
  1908. _log.warning(getClass().getSimpleName() + ": The item " + item.getObjectId() + " that is being returned to the owner doesnt belong to the auction house");
  1909. return;
  1910. }
  1911.  
  1912. ThreadPoolManager.getInstance().scheduleGeneral(new ReturnItemsToOwnerThread(container, item), 100);
  1913. }
  1914.  
  1915. private class ReturnItemsToOwnerThread implements Runnable
  1916. {
  1917. private final ItemContainer _container;
  1918. private final AuctionHouseEntranceItem _item;
  1919.  
  1920. public ReturnItemsToOwnerThread(ItemContainer container, AuctionHouseEntranceItem item)
  1921. {
  1922. _container = container;
  1923. _item = item;
  1924. }
  1925.  
  1926. @Override
  1927. public void run()
  1928. {
  1929. synchronized (_entrancesById)
  1930. {
  1931. final String message = "Your item couldn't be sold on the set period, so it's now returning to you\nThanks for using our Auction House system";
  1932. final Message msg = new Message(null, _item.getCharId(), "Auction House Return", message, Message.SendBySystem.NONE);
  1933. final Mail attachments = msg.createAttachments();
  1934. final ItemInstance newItem = _container.transferItem("AuctionHouse", _item.getObjectId(), _item.getQuantity(), attachments, null, null);
  1935. if (newItem == null)
  1936. {
  1937. _log.warning(getClass().getSimpleName() + ": Error adding attachment item " + _item.getObjectId() + " for char " + _item.getCharId() + " (newitem == null)");
  1938. return;
  1939. }
  1940. newItem.setLocation(newItem.getLocation(), msg.getId());
  1941.  
  1942. MailManager.getInstance().sendMessage(msg);
  1943.  
  1944. modifyAuctionItemCountToDB(_item, -1);
  1945. }
  1946. }
  1947. }
  1948.  
  1949. private void addNewAuctionToDB(L2PcInstance activeChar, ItemInstance item, int quantity, int salePrice, int duration)
  1950. {
  1951. final AuctionHouse entrance = AuctionHouse.getEntranceIdFromItem(item);
  1952. final AuctionHouseEntranceItem newItem = new AuctionHouseEntranceItem(entrance.getTopId(), activeChar.getObjectId(), item, quantity, salePrice, System.currentTimeMillis() + (duration * 24 * 60 * 60 * 1000));
  1953. _entrancesById.get(entrance.getTopId()).addItem(newItem);
  1954.  
  1955. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  1956. PreparedStatement statement = con.prepareStatement("INSERT INTO auction_house VALUES (?,?,?,?,?)"))
  1957. {
  1958. statement.setInt(1, newItem.getObjectId());
  1959. statement.setInt(2, newItem.getCharId());
  1960. statement.setInt(3, newItem.getQuantity());
  1961. statement.setLong(4, newItem.getPrice());
  1962. statement.setLong(5, newItem.getEndTime());
  1963. statement.execute();
  1964. }
  1965. catch (Exception e)
  1966. {
  1967. _log.warning(getClass().getSimpleName() + ": No se pudo agregar el nuevo auction a la DB!:" + e);
  1968. }
  1969. }
  1970.  
  1971. protected void modifyAuctionItemCountToDB(AuctionHouseEntranceItem item, int newCount)
  1972. {
  1973. item.setQuantity(newCount);
  1974.  
  1975. if (item.getQuantity() <= 0)
  1976. {
  1977. _entrancesById.get(item.getTopId()).getItems().remove(item);
  1978.  
  1979. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  1980. PreparedStatement statement = con.prepareStatement("DELETE FROM auction_house WHERE itemId=?"))
  1981. {
  1982. statement.setInt(1, item.getObjectId());
  1983. statement.execute();
  1984. }
  1985. catch (Exception e)
  1986. {
  1987. _log.warning(getClass().getSimpleName() + ": No se pudo eliminar el auction de la DB:" + e);
  1988. }
  1989. }
  1990. else
  1991. {
  1992. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  1993. PreparedStatement statement = con.prepareStatement("UPDATE auction_house SET count=? WHERE itemId=?"))
  1994. {
  1995. statement.setInt(1, item.getQuantity());
  1996. statement.setInt(2, item.getObjectId());
  1997. statement.executeUpdate();
  1998. }
  1999. catch (Exception e)
  2000. {
  2001. _log.warning(getClass().getSimpleName() + ": No se pudo actualizar el auction de la DB:" + e);
  2002. }
  2003. }
  2004. }
  2005.  
  2006. private static String getCompleteItemName(ItemInstance item, boolean showCompleteInfo, boolean showIcons)
  2007. {
  2008. if (showIcons)
  2009. {
  2010. final StringBuilder builder = new StringBuilder();
  2011.  
  2012. if (item.getEnchantLevel() > 0)
  2013. {
  2014. builder.append("<font color=a09675>+" + item.getEnchantLevel() + "</font> ");
  2015. }
  2016.  
  2017. final String[] parts = item.getItem().getName().split(" - ");
  2018. if (parts.length > 2)
  2019. {
  2020. builder.append("<font color=fcf900>" + parts[0] + " - " + parts[1] + "</font> <font color=d3aa4e>" + parts[2] + "</font> ");
  2021. }
  2022. else if (parts.length > 1)
  2023. {
  2024. builder.append(parts[0] + " <font color=d3aa4e>" + parts[1] + "</font> ");
  2025. }
  2026. else
  2027. {
  2028. builder.append(parts[0] + " ");
  2029. }
  2030.  
  2031. return builder.toString();
  2032. }
  2033.  
  2034. if (showCompleteInfo)
  2035. {
  2036. final StringBuilder builder = new StringBuilder();
  2037.  
  2038. if (item.getEnchantLevel() > 0)
  2039. {
  2040. builder.append("<font color=a09675>+" + item.getEnchantLevel() + "</font> ");
  2041. }
  2042.  
  2043. final String[] parts = item.getItem().getName().split(" - ");
  2044. if (parts.length > 2)
  2045. {
  2046. builder.append("<font color=fcf900>" + parts[0] + " - " + parts[1] + "</font> <font color=d3aa4e>" + parts[2] + "</font> ");
  2047. }
  2048. else if (parts.length > 1)
  2049. {
  2050. builder.append(parts[0] + " <font color=d3aa4e>" + parts[1] + "</font> ");
  2051. }
  2052. else
  2053. {
  2054. builder.append(parts[0] + " ");
  2055. }
  2056.  
  2057. return builder.toString();
  2058. }
  2059.  
  2060. return (item.getEnchantLevel() > 0 ? "+" + item.getEnchantLevel() + " " : "") + item.getItem().getName();
  2061. }
  2062.  
  2063. /**
  2064. * @param player
  2065. * @param count
  2066. * @param price
  2067. * @param duration
  2068. * @return Calcula cuanto seria el fee para poner ese item en el auction house
  2069. */
  2070. private static double calculateSaleFee(L2PcInstance player, int count, long price, int duration)
  2071. {
  2072. // El precio que se cobra es igual a: quantity * salePrice * cantidadDias * 0.5%
  2073. double fee = count * price * duration * Config.AUCTION_HOUSE_SALE_FEE;
  2074.  
  2075. // Lo minimo que se cobra como fee son 10k
  2076. return Math.max(10000, fee);
  2077. }
  2078.  
  2079. public static AuctionHouseManager01 getInstance()
  2080. {
  2081. return SingletonHolder._instance;
  2082. }
  2083.  
  2084. private static class SingletonHolder
  2085. {
  2086. protected static final AuctionHouseManager01 _instance = new AuctionHouseManager01();
  2087. }
  2088.  
  2089. public static class AuctionHouseEntrance
  2090. {
  2091. private final int _topId;
  2092. private final String _name;
  2093. private final String _category;
  2094. private final ArrayList<AuctionHouseEntranceItem> _items = new ArrayList<>();
  2095.  
  2096. public AuctionHouseEntrance(int topId, String name, String category)
  2097. {
  2098. _topId = topId;
  2099. _name = name;
  2100. _category = category;
  2101. }
  2102.  
  2103. public int getTopId()
  2104. {
  2105. return _topId;
  2106. }
  2107.  
  2108. public String getTopName()
  2109. {
  2110. return _name;
  2111. }
  2112.  
  2113. public String getCategory()
  2114. {
  2115. return _category;
  2116. }
  2117.  
  2118. public void addItem(AuctionHouseEntranceItem item)
  2119. {
  2120. _items.add(item);
  2121. }
  2122.  
  2123. public void cleanItems()
  2124. {
  2125. _items.clear();
  2126. }
  2127.  
  2128. public ArrayList<AuctionHouseEntranceItem> getItems()
  2129. {
  2130. return _items;
  2131. }
  2132. }
  2133.  
  2134. public static class AuctionHouseEntranceItem
  2135. {
  2136. private final int _topId;
  2137. private final int _charId;
  2138. private final int _objectId;
  2139. private final ItemInstance _item;
  2140. private int _quantity;
  2141. private final int _price;
  2142. private final long _endTime;
  2143. private volatile boolean _isRemoved = false;
  2144.  
  2145. public AuctionHouseEntranceItem(int topId, int charId, ItemInstance item, int quantity, int price, long endTime)
  2146. {
  2147. _topId = topId;
  2148. _charId = charId;
  2149. _objectId = item.getObjectId();
  2150. _item = item;
  2151. _quantity = quantity;
  2152. _price = price;
  2153. _endTime = endTime;
  2154. }
  2155.  
  2156. public void setQuantity(int count)
  2157. {
  2158. _quantity = count;
  2159. }
  2160.  
  2161. public int getTopId()
  2162. {
  2163. return _topId;
  2164. }
  2165.  
  2166. public int getCharId()
  2167. {
  2168. return _charId;
  2169. }
  2170.  
  2171. public int getObjectId()
  2172. {
  2173. return _objectId;
  2174. }
  2175.  
  2176. public ItemInstance getItemInstance()
  2177. {
  2178. return _item;
  2179. }
  2180.  
  2181. public int getQuantity()
  2182. {
  2183. return _quantity;
  2184. }
  2185.  
  2186. public int getPrice()
  2187. {
  2188. return _price;
  2189. }
  2190.  
  2191. public long getEndTime()
  2192. {
  2193. return _endTime;
  2194. }
  2195.  
  2196. public String getRemainingTimeString()
  2197. {
  2198. final long diffTime = _endTime - System.currentTimeMillis();
  2199. if (diffTime < (60 * 60 * 1000))
  2200. {
  2201. return (int) (diffTime / 60000) + " Minutes";
  2202. }
  2203. if (diffTime < (24 * 60 * 60 * 1000))
  2204. {
  2205. return (int) (diffTime / 3600000) + " Hours";
  2206. }
  2207.  
  2208. return (int) (diffTime / 86400000) + " Days";
  2209. }
  2210.  
  2211. public void setIsRemoved(boolean val)
  2212. {
  2213. _isRemoved = val;
  2214. }
  2215.  
  2216. public boolean isRemoved()
  2217. {
  2218. return _isRemoved;
  2219. }
  2220. }
  2221.  
  2222. // Sorting comparators
  2223. private static final Comparator<AuctionHouseEntranceItem> NAME_ASC_COMPARATOR = new Comparator<AuctionHouseEntranceItem>()
  2224. {
  2225. @Override
  2226. public int compare(final AuctionHouseEntranceItem left, final AuctionHouseEntranceItem right)
  2227. {
  2228. return left.getItemInstance().getItem().getName().compareTo(right.getItemInstance().getItem().getName());
  2229. }
  2230. };
  2231.  
  2232. private static final Comparator<AuctionHouseEntranceItem> NAME_DESC_COMPARATOR = new Comparator<AuctionHouseEntranceItem>()
  2233. {
  2234. @Override
  2235. public int compare(final AuctionHouseEntranceItem left, final AuctionHouseEntranceItem right)
  2236. {
  2237. return -left.getItemInstance().getItem().getName().compareTo(right.getItemInstance().getItem().getName());
  2238. }
  2239. };
  2240.  
  2241. private static final Comparator<AuctionHouseEntranceItem> COUNT_ASC_COMPARATOR = new Comparator<AuctionHouseEntranceItem>()
  2242. {
  2243. @Override
  2244. public int compare(final AuctionHouseEntranceItem left, final AuctionHouseEntranceItem right)
  2245. {
  2246. if (left.getQuantity() > right.getQuantity())
  2247. {
  2248. return 1;
  2249. }
  2250. if (left.getQuantity() < right.getQuantity())
  2251. {
  2252. return -1;
  2253. }
  2254. return 0;
  2255. }
  2256. };
  2257.  
  2258. private static final Comparator<AuctionHouseEntranceItem> COUNT_DESC_COMPARATOR = new Comparator<AuctionHouseEntranceItem>()
  2259. {
  2260. @Override
  2261. public int compare(final AuctionHouseEntranceItem left, final AuctionHouseEntranceItem right)
  2262. {
  2263. if (left.getQuantity() > right.getQuantity())
  2264. {
  2265. return -1;
  2266. }
  2267. if (left.getQuantity() < right.getQuantity())
  2268. {
  2269. return 1;
  2270. }
  2271. return 0;
  2272. }
  2273. };
  2274.  
  2275. private static final Comparator<AuctionHouseEntranceItem> PRICE_ASC_COMPARATOR = new Comparator<AuctionHouseEntranceItem>()
  2276. {
  2277. @Override
  2278. public int compare(final AuctionHouseEntranceItem left, final AuctionHouseEntranceItem right)
  2279. {
  2280. if (left.getPrice() > right.getPrice())
  2281. {
  2282. return 1;
  2283. }
  2284. if (left.getPrice() < right.getPrice())
  2285. {
  2286. return -1;
  2287. }
  2288. return 0;
  2289. }
  2290. };
  2291.  
  2292. private static final Comparator<AuctionHouseEntranceItem> PRICE_DESC_COMPARATOR = new Comparator<AuctionHouseEntranceItem>()
  2293. {
  2294. @Override
  2295. public int compare(final AuctionHouseEntranceItem left, final AuctionHouseEntranceItem right)
  2296. {
  2297. if (left.getPrice() > right.getPrice())
  2298. {
  2299. return -1;
  2300. }
  2301. if (left.getPrice() < right.getPrice())
  2302. {
  2303. return 1;
  2304. }
  2305. return 0;
  2306. }
  2307. };
  2308. }
Add Comment
Please, Sign In to add comment