SkillTable.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.datatables;
  16. import java.util.Map;
  17. import javolution.util.FastList;
  18. import javolution.util.FastMap;
  19. import net.sf.l2j.gameserver.model.L2Skill;
  20. import net.sf.l2j.gameserver.skills.SkillsEngine;
  21. /**
  22. * This class ...
  23. *
  24. * @version $Revision: 1.8.2.6.2.18 $ $Date: 2005/04/06 16:13:25 $
  25. */
  26. public class SkillTable
  27. {
  28. //private static Logger _log = Logger.getLogger(SkillTable.class.getName());
  29. private static Map<Integer, L2Skill> _skills = new FastMap<Integer, L2Skill>();
  30. private boolean _initialized = true;
  31. public static SkillTable getInstance()
  32. {
  33. return SingletonHolder._instance;
  34. }
  35. private SkillTable()
  36. {
  37. SkillsEngine.getInstance().loadAllSkills(_skills);
  38. }
  39. public void reload()
  40. {
  41. final Map<Integer, L2Skill> skills = new FastMap<Integer, L2Skill>();
  42. SkillsEngine.getInstance().loadAllSkills(skills);
  43. _skills = skills;
  44. }
  45. public boolean isInitialized()
  46. {
  47. return _initialized;
  48. }
  49. /**
  50. * Provides the skill hash
  51. * @param skill The L2Skill to be hashed
  52. * @return SkillTable.getSkillHashCode(skill.getId(), skill.getLevel())
  53. */
  54. public static int getSkillHashCode(L2Skill skill)
  55. {
  56. return SkillTable.getSkillHashCode(skill.getId(), skill.getLevel());
  57. }
  58. /**
  59. * Centralized method for easier change of the hashing sys
  60. * @param skillId The Skill Id
  61. * @param skillLevel The Skill Level
  62. * @return The Skill hash number
  63. */
  64. public static int getSkillHashCode(int skillId, int skillLevel)
  65. {
  66. return skillId * 1021 + skillLevel;
  67. }
  68. public L2Skill getInfo(int skillId, int level)
  69. {
  70. return _skills.get(getSkillHashCode(skillId, level));
  71. }
  72. public int getMaxLevel(int magicId, int level)
  73. {
  74. while (level < 100)
  75. {
  76. if (_skills.get(getSkillHashCode(magicId, ++level)) == null)
  77. return level - 1;
  78. }
  79. return level;
  80. }
  81. /**
  82. * Returns an array with siege skills. If addNoble == true, will add also Advanced headquarters.
  83. */
  84. public L2Skill[] getSiegeSkills(boolean addNoble)
  85. {
  86. FastList<L2Skill> list = new FastList<L2Skill>();
  87. list.add(_skills.get(SkillTable.getSkillHashCode(246, 1)));
  88. list.add(_skills.get(SkillTable.getSkillHashCode(247, 1)));
  89. if (addNoble)
  90. list.add(_skills.get(SkillTable.getSkillHashCode(326, 1)));
  91. L2Skill[] temp = new L2Skill[list.size()];
  92. list.toArray(temp);
  93. return temp;
  94. }
  95. @SuppressWarnings("synthetic-access")
  96. private static class SingletonHolder
  97. {
  98. protected static final SkillTable _instance = new SkillTable();
  99. }
  100. }