L2Multisell.java 25 KB

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