2
0

ExtractableSkillsData.java 5.0 KB

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