ExtractableSkillsData.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. /**
  16. *
  17. * @author FBIagent
  18. *
  19. */
  20. package com.l2jserver.gameserver.datatables;
  21. import gnu.trove.TIntObjectHashMap;
  22. import java.io.File;
  23. import java.util.Scanner;
  24. import java.util.logging.Logger;
  25. import javolution.util.FastList;
  26. import com.l2jserver.Config;
  27. import com.l2jserver.gameserver.model.L2ExtractableProductItem;
  28. import com.l2jserver.gameserver.model.L2ExtractableSkill;
  29. import com.l2jserver.gameserver.model.L2Skill;
  30. public class ExtractableSkillsData
  31. {
  32. protected static final Logger _log = Logger.getLogger(ExtractableSkillsData.class.getName());
  33. private final TIntObjectHashMap<L2ExtractableSkill> _items = new TIntObjectHashMap<L2ExtractableSkill>();
  34. public static ExtractableSkillsData getInstance()
  35. {
  36. return SingletonHolder._instance;
  37. }
  38. public ExtractableSkillsData()
  39. {
  40. loadExtractableSkills();
  41. }
  42. public L2ExtractableSkill getExtractableItem(L2Skill skill)
  43. {
  44. return _items.get(SkillTable.getSkillHashCode(skill));
  45. }
  46. public void reload()
  47. {
  48. loadExtractableSkills();
  49. }
  50. private void loadExtractableSkills()
  51. {
  52. Scanner s;
  53. try
  54. {
  55. s = new Scanner(new File(Config.DATAPACK_ROOT + "/data/extractable_skills.csv"));
  56. }
  57. catch (Exception e)
  58. {
  59. _log.warning("Extractable items data: Can not find '" + Config.DATAPACK_ROOT + "/data/extractable_skills.csv'");
  60. return;
  61. }
  62. _items.clear();
  63. int lineCount = 0;
  64. while (s.hasNextLine())
  65. {
  66. lineCount++;
  67. String line = s.nextLine().trim();
  68. if (line.startsWith("#"))
  69. continue;
  70. else if (line.isEmpty())
  71. continue;
  72. String[] lineSplit = line.split(";");
  73. boolean ok = true;
  74. int skillID = 0;
  75. int skillLvl = 0;
  76. try
  77. {
  78. skillID = Integer.parseInt(lineSplit[0]);
  79. skillLvl = Integer.parseInt(lineSplit[1]);
  80. }
  81. catch (Exception e)
  82. {
  83. _log.warning("Extractable skills data: Error in line " + lineCount + " -> invalid item id or wrong seperator after skill id!");
  84. _log.warning(" " + line);
  85. ok = false;
  86. }
  87. L2Skill skill = SkillTable.getInstance().getInfo(skillID, skillLvl);
  88. if (skill == null)
  89. {
  90. _log.warning("Extractable skills data: Error in line " + lineCount + " -> skill is null!");
  91. _log.warning(" " + line);
  92. ok = false;
  93. }
  94. if (!ok)
  95. continue;
  96. FastList<L2ExtractableProductItem> product_temp = new FastList<L2ExtractableProductItem>();
  97. for (int i = 1; i < lineSplit.length -1 ; i++)
  98. {
  99. ok = true;
  100. String[] lineSplit2 = lineSplit[i + 1].split(",");
  101. if (lineSplit2.length < 3 )//|| lineSplit2.length-1 %2 != 0)
  102. {
  103. _log.warning("Extractable skills data: Error in line " + lineCount + " -> wrong seperator!");
  104. _log.warning(" " + line);
  105. ok = false;
  106. }
  107. if (!ok)
  108. continue;
  109. int[] production =null;
  110. int[] amount = null;
  111. int chance = 0;
  112. try
  113. {
  114. int k =0;
  115. production = new int[(lineSplit2.length-1)/2];
  116. amount = new int[(lineSplit2.length-1)/2];
  117. for (int j = 0; j < lineSplit2.length-1; j++)
  118. {
  119. production[k] = Integer.parseInt(lineSplit2[j]);
  120. amount[k] = Integer.parseInt(lineSplit2[j+=1]);
  121. k++;
  122. }
  123. chance = Integer.parseInt(lineSplit2[lineSplit2.length-1]);
  124. }
  125. catch (Exception e)
  126. {
  127. _log.warning("Extractable skills data: Error in line " + lineCount + " -> incomplete/invalid production data or wrong seperator!");
  128. _log.warning(" " + line);
  129. ok = false;
  130. }
  131. if (!ok)
  132. continue;
  133. L2ExtractableProductItem product = new L2ExtractableProductItem(production, amount, chance);
  134. product_temp.add(product);
  135. }
  136. int fullChances = 0;
  137. for (L2ExtractableProductItem Pi : product_temp)
  138. fullChances += Pi.getChance();
  139. if (fullChances > 100)
  140. {
  141. _log.warning("Extractable skills data: Error in line " + lineCount + " -> all chances together are more then 100!");
  142. _log.warning(" " + line);
  143. continue;
  144. }
  145. int hash = SkillTable.getSkillHashCode(skill);
  146. L2ExtractableSkill product = new L2ExtractableSkill(hash, product_temp);
  147. _items.put(hash, product);
  148. }
  149. s.close();
  150. _log.info("Extractable skills data: Loaded " + _items.size() + " extractable skills!");
  151. }
  152. private static class SingletonHolder
  153. {
  154. protected static final ExtractableSkillsData _instance = new ExtractableSkillsData();
  155. }
  156. }