L2Multisell.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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 com.l2jserver.gameserver.model;
  16. import java.io.File;
  17. import java.util.List;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import javax.xml.parsers.DocumentBuilderFactory;
  21. import javolution.util.FastList;
  22. import org.w3c.dom.Document;
  23. import org.w3c.dom.Node;
  24. import com.l2jserver.Config;
  25. import com.l2jserver.gameserver.datatables.ItemTable;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.network.serverpackets.MultiSellList;
  28. import com.l2jserver.gameserver.templates.item.L2Armor;
  29. import com.l2jserver.gameserver.templates.item.L2Item;
  30. import com.l2jserver.gameserver.templates.item.L2Weapon;
  31. /**
  32. * Multisell list manager
  33. *
  34. */
  35. public class L2Multisell
  36. {
  37. private static Logger _log = Logger.getLogger(L2Multisell.class.getName());
  38. private List<MultiSellListContainer> _entries = new FastList<MultiSellListContainer>();
  39. public MultiSellListContainer getList(int id)
  40. {
  41. synchronized (_entries)
  42. {
  43. for (MultiSellListContainer list : _entries)
  44. {
  45. if (list.getListId() == id)
  46. return list;
  47. }
  48. }
  49. _log.warning("[L2Multisell] can't find list with id: " + id);
  50. return null;
  51. }
  52. private L2Multisell()
  53. {
  54. parseData();
  55. }
  56. public void reload()
  57. {
  58. parseData();
  59. }
  60. public static L2Multisell getInstance()
  61. {
  62. return SingletonHolder._instance;
  63. }
  64. private void parseData()
  65. {
  66. _entries.clear();
  67. parse();
  68. _log.info("L2Multisell: Loaded " + _entries.size() + " lists.");
  69. }
  70. /**
  71. * This will generate the multisell list for the items. There exist various
  72. * parameters in multisells that affect the way they will appear:
  73. * 1) inventory only:
  74. * * if true, only show items of the multisell for which the
  75. * "primary" ingredients are already in the player's inventory. By "primary"
  76. * ingredients we mean weapon and armor.
  77. * * if false, show the entire list.
  78. * 2) maintain enchantment: presumably, only lists with "inventory only" set to true
  79. * should sometimes have this as true. This makes no sense otherwise...
  80. * * If true, then the product will match the enchantment level of the ingredient.
  81. * if the player has multiple items that match the ingredient list but the enchantment
  82. * levels differ, then the entries need to be duplicated to show the products and
  83. * ingredients for each enchantment level.
  84. * For example: If the player has a crystal staff +1 and a crystal staff +3 and goes
  85. * to exchange it at the mammon, the list should have all exchange possibilities for
  86. * the +1 staff, followed by all possibilities for the +3 staff.
  87. * * If false, then any level ingredient will be considered equal and product will always
  88. * be at +0
  89. * 3) apply taxes: Uses the "taxIngredient" entry in order to add a certain amount of adena to the ingredients
  90. *
  91. * @see com.l2jserver.util.network.BaseSendablePacket.ServerBasePacket#runImpl()
  92. */
  93. private MultiSellListContainer generateMultiSell(int listId, boolean inventoryOnly, L2PcInstance player, int npcId, double taxRate)
  94. {
  95. MultiSellListContainer listTemplate = L2Multisell.getInstance().getList(listId);
  96. MultiSellListContainer list = new MultiSellListContainer();
  97. if (listTemplate == null)
  98. return list;
  99. list = L2Multisell.getInstance().new MultiSellListContainer();
  100. list.setListId(listId);
  101. if (npcId != 0 && !listTemplate.checkNpcId(npcId))
  102. listTemplate.addNpcId(npcId);
  103. if (inventoryOnly)
  104. {
  105. if (player == null)
  106. return list;
  107. L2ItemInstance[] items;
  108. if (listTemplate.getMaintainEnchantment())
  109. items = player.getInventory().getUniqueItemsByEnchantLevel(false, false, false);
  110. else
  111. items = player.getInventory().getUniqueItems(false, false, false);
  112. int enchantLevel, elementId, elementValue, augmentId, fireVal, waterVal, windVal, earthVal, holyVal, darkVal;
  113. for (L2ItemInstance item : items)
  114. {
  115. // only do the matchup on equipable items that are not currently equipped
  116. // so for each appropriate item, produce a set of entries for the multisell list.
  117. if (!item.isEquipped() && ((item.getItem() instanceof L2Armor) || (item.getItem() instanceof L2Weapon)))
  118. {
  119. enchantLevel = (listTemplate.getMaintainEnchantment() ? item.getEnchantLevel() : 0);
  120. augmentId = (listTemplate.getMaintainEnchantment() ? (item.getAugmentation() != null ? item.getAugmentation().getAugmentationId() : 0) : 0);
  121. elementId = (listTemplate.getMaintainEnchantment() ? item.getAttackElementType() : -2);
  122. elementValue = (listTemplate.getMaintainEnchantment() ? item.getAttackElementPower() : 0);
  123. fireVal = (listTemplate.getMaintainEnchantment() ? item.getElementDefAttr(Elementals.FIRE) : 0);
  124. waterVal = (listTemplate.getMaintainEnchantment() ? item.getElementDefAttr(Elementals.WATER) : 0);
  125. windVal = (listTemplate.getMaintainEnchantment() ? item.getElementDefAttr(Elementals.WIND) : 0);
  126. earthVal = (listTemplate.getMaintainEnchantment() ? item.getElementDefAttr(Elementals.EARTH) : 0);
  127. holyVal = (listTemplate.getMaintainEnchantment() ? item.getElementDefAttr(Elementals.HOLY) : 0);
  128. darkVal = (listTemplate.getMaintainEnchantment() ? item.getElementDefAttr(Elementals.DARK) : 0);
  129. // loop through the entries to see which ones we wish to include
  130. for (MultiSellEntry ent : listTemplate.getEntries())
  131. {
  132. boolean doInclude = false;
  133. // check ingredients of this entry to see if it's an entry we'd like to include.
  134. for (MultiSellIngredient ing : ent.getIngredients())
  135. {
  136. if (item.getItemId() == ing.getItemId())
  137. {
  138. doInclude = true;
  139. break;
  140. }
  141. }
  142. // manipulate the ingredients of the template entry for this particular instance shown
  143. // i.e: Assign enchant levels and/or apply taxes as needed.
  144. if (doInclude)
  145. list.addEntry(prepareEntry(ent, listTemplate.getApplyTaxes(), listTemplate.getMaintainEnchantment(), enchantLevel, augmentId, elementId, elementValue, fireVal, waterVal, windVal, earthVal, holyVal, darkVal, taxRate));
  146. }
  147. }
  148. } // end for each inventory item.
  149. } // end if "inventory-only"
  150. else
  151. // this is a list-all type
  152. {
  153. // if no taxes are applied, no modifications are needed
  154. for (MultiSellEntry ent : listTemplate.getEntries())
  155. list.addEntry(prepareEntry(ent, listTemplate.getApplyTaxes(), false, 0, 0, -2, 0, 0, 0, 0, 0, 0, 0, taxRate));
  156. }
  157. return list;
  158. }
  159. // Regarding taxation, the following is the case:
  160. // a) The taxes come out purely from the adena TaxIngredient
  161. // b) If the entry has no adena ingredients other than the taxIngredient, the resulting
  162. // amount of adena is appended to the entry
  163. // c) If the entry already has adena as an entry, the taxIngredient is used in order to increase
  164. // the count for the existing adena ingredient
  165. private MultiSellEntry prepareEntry(MultiSellEntry templateEntry, boolean applyTaxes, boolean maintainEnchantment, int enchantLevel,
  166. int augmentId, int elementId, int elementValue, int fireValue, int waterValue, int windValue, int earthValue, int holyValue,
  167. int darkValue, double taxRate)
  168. {
  169. MultiSellEntry newEntry = L2Multisell.getInstance().new MultiSellEntry();
  170. newEntry.setEntryId(templateEntry.getEntryId() * 100000 + enchantLevel);
  171. long adenaAmount = 0;
  172. for (MultiSellIngredient ing : templateEntry.getIngredients())
  173. {
  174. // load the ingredient from the template
  175. MultiSellIngredient newIngredient = L2Multisell.getInstance().new MultiSellIngredient(ing);
  176. // if taxes are to be applied, modify/add the adena count based on the template adena/ancient adena count
  177. if (ing.getItemId() == 57 && ing.isTaxIngredient())
  178. {
  179. if (applyTaxes)
  180. adenaAmount += Math.round(ing.getItemCount() * taxRate);
  181. continue; // do not adena yet, as non-taxIngredient adena entries might occur next (order not guaranteed)
  182. }
  183. else if (ing.getItemId() == 57) // && !ing.isTaxIngredient()
  184. {
  185. adenaAmount += ing.getItemCount();
  186. continue; // do not adena yet, as taxIngredient adena entries might occur next (order not guaranteed)
  187. }
  188. // if it is an armor/weapon, modify the enchantment level appropriately, if necessary
  189. // not used for clan reputation and fame
  190. else if (maintainEnchantment && newIngredient.getItemId() > 0)
  191. {
  192. L2Item tempItem = ItemTable.getInstance().createDummyItem(ing.getItemId()).getItem();
  193. if ((tempItem instanceof L2Armor) || (tempItem instanceof L2Weapon))
  194. {
  195. newIngredient.setEnchantmentLevel(enchantLevel);
  196. newIngredient.setAugmentId(augmentId);
  197. newIngredient.setElementId(elementId);
  198. newIngredient.setElementValue(elementValue);
  199. newIngredient.setFireValue(fireValue);
  200. newIngredient.setWaterValue(waterValue);
  201. newIngredient.setWindValue(windValue);
  202. newIngredient.setEarthValue(earthValue);
  203. newIngredient.setHolyValue(holyValue);
  204. newIngredient.setDarkValue(darkValue);
  205. }
  206. }
  207. // finally, add this ingredient to the entry
  208. newEntry.addIngredient(newIngredient);
  209. }
  210. // now add the adena, if any.
  211. if (adenaAmount > 0)
  212. {
  213. newEntry.addIngredient(L2Multisell.getInstance().new MultiSellIngredient(57, adenaAmount, 0, 0, -2, 0, 0, 0, 0, 0, 0, 0, false, false));
  214. }
  215. // Now modify the enchantment level of products, if necessary
  216. for (MultiSellIngredient ing : templateEntry.getProducts())
  217. {
  218. // load the ingredient from the template
  219. MultiSellIngredient newIngredient = L2Multisell.getInstance().new MultiSellIngredient(ing);
  220. if (maintainEnchantment)
  221. {
  222. // if it is an armor/weapon, modify the enchantment level appropriately
  223. // (note, if maintain enchantment is "false" this modification will result to a +0)
  224. L2Item tempItem = ItemTable.getInstance().createDummyItem(ing.getItemId()).getItem();
  225. if ((tempItem instanceof L2Armor) || (tempItem instanceof L2Weapon))
  226. {
  227. newIngredient.setEnchantmentLevel(enchantLevel);
  228. newIngredient.setAugmentId(augmentId);
  229. newIngredient.setElementId(elementId);
  230. newIngredient.setElementValue(elementValue);
  231. newIngredient.setFireValue(fireValue);
  232. newIngredient.setWaterValue(waterValue);
  233. newIngredient.setWindValue(windValue);
  234. newIngredient.setEarthValue(earthValue);
  235. newIngredient.setHolyValue(holyValue);
  236. newIngredient.setDarkValue(darkValue);
  237. }
  238. }
  239. newEntry.addProduct(newIngredient);
  240. }
  241. return newEntry;
  242. }
  243. public void separateAndSend(int listId, L2PcInstance player, int npcId, boolean inventoryOnly, double taxRate)
  244. {
  245. MultiSellListContainer list = generateMultiSell(listId, inventoryOnly, player, npcId, taxRate);
  246. MultiSellListContainer temp = new MultiSellListContainer();
  247. int page = 1;
  248. temp.setListId(list.getListId());
  249. for (MultiSellEntry e : list.getEntries())
  250. {
  251. if (temp.getEntries().size() == 40)
  252. {
  253. player.sendPacket(new MultiSellList(temp, page++, 0));
  254. temp = new MultiSellListContainer();
  255. temp.setListId(list.getListId());
  256. }
  257. temp.addEntry(e);
  258. }
  259. player.sendPacket(new MultiSellList(temp, page, 1));
  260. }
  261. public class MultiSellEntry
  262. {
  263. private int _entryId;
  264. private List<MultiSellIngredient> _products = new FastList<MultiSellIngredient>();
  265. private List<MultiSellIngredient> _ingredients = new FastList<MultiSellIngredient>();
  266. /**
  267. * @param entryId The entryId to set.
  268. */
  269. public void setEntryId(int entryId)
  270. {
  271. _entryId = entryId;
  272. }
  273. /**
  274. * @return Returns the entryId.
  275. */
  276. public int getEntryId()
  277. {
  278. return _entryId;
  279. }
  280. /**
  281. * @param product The product to add.
  282. */
  283. public void addProduct(MultiSellIngredient product)
  284. {
  285. _products.add(product);
  286. }
  287. /**
  288. * @return Returns the products.
  289. */
  290. public List<MultiSellIngredient> getProducts()
  291. {
  292. return _products;
  293. }
  294. /**
  295. * @param ingredients The ingredients to set.
  296. */
  297. public void addIngredient(MultiSellIngredient ingredient)
  298. {
  299. _ingredients.add(ingredient);
  300. }
  301. /**
  302. * @return Returns the ingredients.
  303. */
  304. public List<MultiSellIngredient> getIngredients()
  305. {
  306. return _ingredients;
  307. }
  308. public int stackable()
  309. {
  310. for (MultiSellIngredient p : _products)
  311. {
  312. if (p.getItemId() > 0)
  313. {
  314. L2Item template = ItemTable.getInstance().getTemplate(p.getItemId());
  315. if (template != null && !template.isStackable())
  316. return 0;
  317. }
  318. }
  319. return 1;
  320. }
  321. }
  322. public class MultiSellIngredient
  323. {
  324. private int _itemId, _enchantmentLevel, _element, _elementVal, _augment, _fireVal, _waterVal, _windVal, _earthVal, _holyVal, _darkVal;
  325. private long _itemCount;
  326. private boolean _isTaxIngredient, _mantainIngredient;
  327. public MultiSellIngredient(int itemId, long itemCount, boolean isTaxIngredient, boolean mantainIngredient)
  328. {
  329. this(itemId, itemCount, 0, 0, -2, 0, 0, 0, 0, 0, 0, 0, isTaxIngredient, mantainIngredient);
  330. }
  331. public MultiSellIngredient(int itemId, long itemCount, int enchantmentLevel, int augmentId, int elementId, int elementVal,
  332. int fireVal, int waterVal, int windVal, int earthVal, int holyVal, int darkVal, boolean isTaxIngredient,
  333. boolean mantainIngredient)
  334. {
  335. setItemId(itemId);
  336. setItemCount(itemCount);
  337. setEnchantmentLevel(enchantmentLevel);
  338. setAugmentId(augmentId);
  339. setElementId(elementId);
  340. setElementValue(elementVal);
  341. setFireValue(fireVal);
  342. setWaterValue(waterVal);
  343. setWindValue(windVal);
  344. setEarthValue(earthVal);
  345. setHolyValue(holyVal);
  346. setDarkValue(darkVal);
  347. setIsTaxIngredient(isTaxIngredient);
  348. setMantainIngredient(mantainIngredient);
  349. }
  350. public MultiSellIngredient(MultiSellIngredient e)
  351. {
  352. _itemId = e.getItemId();
  353. _itemCount = e.getItemCount();
  354. _enchantmentLevel = e.getEnchantmentLevel();
  355. _isTaxIngredient = e.isTaxIngredient();
  356. _mantainIngredient = e.getMantainIngredient();
  357. _augment = e.getAugmentId();
  358. _element = e.getElementId();
  359. _elementVal = e.getElementVal();
  360. _fireVal = e.getFireVal();
  361. _waterVal = e.getWaterVal();
  362. _windVal = e.getWindVal();
  363. _earthVal = e.getEarthVal();
  364. _holyVal = e.getHolyVal();
  365. _darkVal = e.getDarkVal();
  366. }
  367. public void setAugmentId(int augment)
  368. {
  369. _augment = augment;
  370. }
  371. public void setElementId(int element)
  372. {
  373. _element = element;
  374. }
  375. public void setElementValue(int elementVal)
  376. {
  377. _elementVal = elementVal;
  378. }
  379. public void setFireValue(int val)
  380. {
  381. _fireVal = val;
  382. }
  383. public void setWaterValue(int val)
  384. {
  385. _waterVal = val;
  386. }
  387. public void setWindValue(int val)
  388. {
  389. _windVal = val;
  390. }
  391. public void setEarthValue(int val)
  392. {
  393. _earthVal = val;
  394. }
  395. public void setHolyValue(int val)
  396. {
  397. _holyVal = val;
  398. }
  399. public void setDarkValue(int val)
  400. {
  401. _darkVal = val;
  402. }
  403. public int getAugmentId()
  404. {
  405. return _augment;
  406. }
  407. public int getElementId()
  408. {
  409. return _element;
  410. }
  411. public int getElementVal()
  412. {
  413. return _elementVal;
  414. }
  415. public int getFireVal()
  416. {
  417. return _fireVal;
  418. }
  419. public int getWaterVal()
  420. {
  421. return _waterVal;
  422. }
  423. public int getWindVal()
  424. {
  425. return _windVal;
  426. }
  427. public int getEarthVal()
  428. {
  429. return _earthVal;
  430. }
  431. public int getHolyVal()
  432. {
  433. return _holyVal;
  434. }
  435. public int getDarkVal()
  436. {
  437. return _darkVal;
  438. }
  439. /**
  440. * @param itemId The itemId to set.
  441. */
  442. public void setItemId(int itemId)
  443. {
  444. _itemId = itemId;
  445. }
  446. /**
  447. * @return Returns the itemId.
  448. */
  449. public int getItemId()
  450. {
  451. return _itemId;
  452. }
  453. /**
  454. * @param itemCount The itemCount to set.
  455. */
  456. public void setItemCount(long itemCount)
  457. {
  458. _itemCount = itemCount;
  459. }
  460. /**
  461. * @return Returns the itemCount.
  462. */
  463. public long getItemCount()
  464. {
  465. return _itemCount;
  466. }
  467. /**
  468. * @param itemCount The itemCount to set.
  469. */
  470. public void setEnchantmentLevel(int enchantmentLevel)
  471. {
  472. _enchantmentLevel = enchantmentLevel;
  473. }
  474. /**
  475. * @return Returns the itemCount.
  476. */
  477. public int getEnchantmentLevel()
  478. {
  479. return _enchantmentLevel;
  480. }
  481. public void setIsTaxIngredient(boolean isTaxIngredient)
  482. {
  483. _isTaxIngredient = isTaxIngredient;
  484. }
  485. public boolean isTaxIngredient()
  486. {
  487. return _isTaxIngredient;
  488. }
  489. public void setMantainIngredient(boolean mantainIngredient)
  490. {
  491. _mantainIngredient = mantainIngredient;
  492. }
  493. public boolean getMantainIngredient()
  494. {
  495. return _mantainIngredient;
  496. }
  497. }
  498. public class MultiSellListContainer
  499. {
  500. private int _listId;
  501. private boolean _applyTaxes = false;
  502. private boolean _maintainEnchantment = false;
  503. private List<Integer> _npcIds;
  504. List<MultiSellEntry> _entriesC;
  505. public MultiSellListContainer()
  506. {
  507. _entriesC = new FastList<MultiSellEntry>();
  508. }
  509. /**
  510. * @param listId The listId to set.
  511. */
  512. public void setListId(int listId)
  513. {
  514. _listId = listId;
  515. }
  516. public void setApplyTaxes(boolean applyTaxes)
  517. {
  518. _applyTaxes = applyTaxes;
  519. }
  520. public void setMaintainEnchantment(boolean maintainEnchantment)
  521. {
  522. _maintainEnchantment = maintainEnchantment;
  523. }
  524. public void addNpcId(int objId)
  525. {
  526. _npcIds.add(objId);
  527. }
  528. /**
  529. * @return Returns the listId.
  530. */
  531. public int getListId()
  532. {
  533. return _listId;
  534. }
  535. public boolean getApplyTaxes()
  536. {
  537. return _applyTaxes;
  538. }
  539. public boolean getMaintainEnchantment()
  540. {
  541. return _maintainEnchantment;
  542. }
  543. public boolean checkNpcId(int npcId)
  544. {
  545. if (_npcIds == null)
  546. {
  547. synchronized (this)
  548. {
  549. if (_npcIds == null)
  550. _npcIds = new FastList<Integer>();
  551. }
  552. return false;
  553. }
  554. return _npcIds.contains(npcId);
  555. }
  556. public void addEntry(MultiSellEntry e)
  557. {
  558. _entriesC.add(e);
  559. }
  560. public List<MultiSellEntry> getEntries()
  561. {
  562. return _entriesC;
  563. }
  564. }
  565. private void hashFiles(String dirname, List<File> hash)
  566. {
  567. File dir = new File(Config.DATAPACK_ROOT, "data/" + dirname);
  568. if (!dir.exists())
  569. {
  570. _log.warning("Dir " + dir.getAbsolutePath() + " not exists");
  571. return;
  572. }
  573. File[] files = dir.listFiles();
  574. for (File f : files)
  575. {
  576. if (f.getName().endsWith(".xml"))
  577. hash.add(f);
  578. }
  579. }
  580. private void parse()
  581. {
  582. Document doc = null;
  583. int id = 0;
  584. List<File> files = new FastList<File>();
  585. hashFiles("multisell", files);
  586. for (File f : files)
  587. {
  588. try
  589. {
  590. id = Integer.parseInt(f.getName().replaceAll(".xml", ""));
  591. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  592. factory.setValidating(false);
  593. factory.setIgnoringComments(true);
  594. doc = factory.newDocumentBuilder().parse(f);
  595. }
  596. catch (Exception e)
  597. {
  598. _log.log(Level.SEVERE, "Error loading file " + f, e);
  599. continue;
  600. }
  601. try
  602. {
  603. MultiSellListContainer list = parseDocument(doc);
  604. list.setListId(id);
  605. _entries.add(list);
  606. }
  607. catch (Exception e)
  608. {
  609. _log.log(Level.SEVERE, "Error in file " + f, e);
  610. }
  611. }
  612. }
  613. protected MultiSellListContainer parseDocument(Document doc)
  614. {
  615. MultiSellListContainer list = new MultiSellListContainer();
  616. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  617. {
  618. if ("list".equalsIgnoreCase(n.getNodeName()))
  619. {
  620. Node attribute;
  621. attribute = n.getAttributes().getNamedItem("applyTaxes");
  622. if (attribute == null)
  623. list.setApplyTaxes(false);
  624. else
  625. list.setApplyTaxes(Boolean.parseBoolean(attribute.getNodeValue()));
  626. attribute = n.getAttributes().getNamedItem("maintainEnchantment");
  627. if (attribute == null)
  628. list.setMaintainEnchantment(false);
  629. else
  630. list.setMaintainEnchantment(Boolean.parseBoolean(attribute.getNodeValue()));
  631. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  632. {
  633. if ("item".equalsIgnoreCase(d.getNodeName()))
  634. {
  635. MultiSellEntry e = parseEntry(d);
  636. list.addEntry(e);
  637. }
  638. }
  639. }
  640. else if ("item".equalsIgnoreCase(n.getNodeName()))
  641. {
  642. MultiSellEntry e = parseEntry(n);
  643. list.addEntry(e);
  644. }
  645. }
  646. return list;
  647. }
  648. protected MultiSellEntry parseEntry(Node n)
  649. {
  650. int entryId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
  651. Node first = n.getFirstChild();
  652. MultiSellEntry entry = new MultiSellEntry();
  653. for (n = first; n != null; n = n.getNextSibling())
  654. {
  655. if ("ingredient".equalsIgnoreCase(n.getNodeName()))
  656. {
  657. Node attribute;
  658. int id = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
  659. long count = Long.parseLong(n.getAttributes().getNamedItem("count").getNodeValue());
  660. boolean isTaxIngredient = false, mantainIngredient = false;
  661. attribute = n.getAttributes().getNamedItem("isTaxIngredient");
  662. if (attribute != null)
  663. isTaxIngredient = Boolean.parseBoolean(attribute.getNodeValue());
  664. attribute = n.getAttributes().getNamedItem("mantainIngredient");
  665. if (attribute != null)
  666. mantainIngredient = Boolean.parseBoolean(attribute.getNodeValue());
  667. MultiSellIngredient e = new MultiSellIngredient(id, count, isTaxIngredient, mantainIngredient);
  668. entry.addIngredient(e);
  669. }
  670. else if ("production".equalsIgnoreCase(n.getNodeName()))
  671. {
  672. int id = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
  673. long count = Long.parseLong(n.getAttributes().getNamedItem("count").getNodeValue());
  674. MultiSellIngredient e = new MultiSellIngredient(id, count, false, false);
  675. entry.addProduct(e);
  676. }
  677. }
  678. entry.setEntryId(entryId);
  679. return entry;
  680. }
  681. @SuppressWarnings("synthetic-access")
  682. private static class SingletonHolder
  683. {
  684. protected static final L2Multisell _instance = new L2Multisell();
  685. }
  686. }