SkillTable.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under the terms of the
  3. * GNU General Public License as published by the Free Software Foundation, either version 3 of the
  4. * License, or (at your option) any later version.
  5. *
  6. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  7. * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  8. * General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with this program. If
  11. * not, see <http://www.gnu.org/licenses/>.
  12. */
  13. package com.l2jserver.gameserver.datatables;
  14. import com.l2jserver.gameserver.model.L2Skill;
  15. import com.l2jserver.gameserver.skills.SkillsEngine;
  16. import gnu.trove.TIntIntHashMap;
  17. import gnu.trove.TIntObjectHashMap;
  18. /**
  19. *
  20. */
  21. public class SkillTable
  22. {
  23. private final TIntObjectHashMap<L2Skill> _skills;
  24. private final TIntIntHashMap _skillMaxLevel;
  25. public static SkillTable getInstance()
  26. {
  27. return SingletonHolder._instance;
  28. }
  29. private SkillTable()
  30. {
  31. _skills = new TIntObjectHashMap<L2Skill>();
  32. _skillMaxLevel = new TIntIntHashMap();
  33. reload();
  34. }
  35. public void reload()
  36. {
  37. _skills.clear();
  38. SkillsEngine.getInstance().loadAllSkills(_skills);
  39. _skillMaxLevel.clear();
  40. for (final L2Skill skill : _skills.getValues(new L2Skill[_skills.size()]))
  41. {
  42. final int skillId = skill.getId();
  43. final int skillLvl = skill.getLevel();
  44. final int maxLvl = _skillMaxLevel.get(skillId);
  45. if (skillLvl > maxLvl)
  46. _skillMaxLevel.put(skillId, skillLvl);
  47. }
  48. //SkillTreeTable.getInstance().reload();
  49. // Reloading as well FrequentSkill enumeration values
  50. for (FrequentSkill sk : FrequentSkill.values())
  51. sk._skill = getInfo(sk._id, sk._level);
  52. }
  53. /**
  54. * Provides the skill hash
  55. *
  56. * @param skill
  57. * The L2Skill to be hashed
  58. * @return getSkillHashCode(skill.getId(), skill.getLevel())
  59. */
  60. public static int getSkillHashCode(L2Skill skill)
  61. {
  62. return getSkillHashCode(skill.getId(), skill.getLevel());
  63. }
  64. /**
  65. * Centralized method for easier change of the hashing sys
  66. *
  67. * @param skillId
  68. * The Skill Id
  69. * @param skillLevel
  70. * The Skill Level
  71. * @return The Skill hash number
  72. */
  73. public static int getSkillHashCode(int skillId, int skillLevel)
  74. {
  75. return skillId * 1021 + skillLevel;
  76. }
  77. public final L2Skill getInfo(final int skillId, final int level)
  78. {
  79. final L2Skill result = _skills.get(getSkillHashCode(skillId, level));
  80. if (result != null)
  81. return result;
  82. // skill/level not found, fix for transformation scripts
  83. final int maxLvl = _skillMaxLevel.get(skillId);
  84. // requested level too high
  85. if (maxLvl > 0 && level > maxLvl)
  86. return _skills.get(getSkillHashCode(skillId, maxLvl));
  87. return null;
  88. }
  89. public final int getMaxLevel(final int skillId)
  90. {
  91. return _skillMaxLevel.get(skillId);
  92. }
  93. /**
  94. * Returns an array with siege skills. If addNoble == true, will add also Advanced headquarters.
  95. */
  96. public L2Skill[] getSiegeSkills(boolean addNoble)
  97. {
  98. L2Skill[] temp = null;
  99. if (addNoble)
  100. {
  101. temp = new L2Skill[3];
  102. temp[2] = _skills.get(SkillTable.getSkillHashCode(326, 1));
  103. }
  104. else
  105. temp = new L2Skill[2];
  106. temp[0] = _skills.get(SkillTable.getSkillHashCode(246, 1));
  107. temp[1] = _skills.get(SkillTable.getSkillHashCode(247, 1));
  108. return temp;
  109. }
  110. @SuppressWarnings("synthetic-access")
  111. private static class SingletonHolder
  112. {
  113. protected static final SkillTable _instance = new SkillTable();
  114. }
  115. /**
  116. * Enum to hold some important references to frequently used (hardcoded) skills in core
  117. *
  118. * @author DrHouse
  119. *
  120. */
  121. public static enum FrequentSkill
  122. {
  123. RAID_CURSE(4215, 1),
  124. RAID_CURSE2(4515, 1),
  125. SEAL_OF_RULER(246, 1),
  126. BUILD_HEADQUARTERS(247, 1),
  127. LUCKY(194, 1),
  128. DWARVEN_CRAFT(1321, 1),
  129. COMMON_CRAFT(1322, 1),
  130. WYVERN_BREATH(4289, 1),
  131. STRIDER_SIEGE_ASSAULT(325, 1),
  132. FAKE_PETRIFICATION(4616, 1),
  133. FIREWORK(5965, 1),
  134. LARGE_FIREWORK(2025, 1),
  135. BLESSING_OF_PROTECTION(5182, 1),
  136. ARENA_CP_RECOVERY(4380, 1),
  137. VOID_BURST(3630, 1),
  138. VOID_FLOW(3631, 1),
  139. THE_VICTOR_OF_WAR(5074, 1),
  140. THE_VANQUISHED_OF_WAR(5075, 1),
  141. SPECIAL_TREE_RECOVERY_BONUS(2139, 1);
  142. private final int _id;
  143. private final int _level;
  144. private L2Skill _skill = null;
  145. private FrequentSkill(int id, int level)
  146. {
  147. _id = id;
  148. _level = level;
  149. }
  150. public L2Skill getSkill()
  151. {
  152. return _skill;
  153. }
  154. }
  155. }