SkillTable.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. FrequentSkill.onReload();
  49. }
  50. /**
  51. * Provides the skill hash
  52. *
  53. * @param skill
  54. * The L2Skill to be hashed
  55. * @return getSkillHashCode(skill.getId(), skill.getLevel())
  56. */
  57. public static int getSkillHashCode(L2Skill skill)
  58. {
  59. return getSkillHashCode(skill.getId(), skill.getLevel());
  60. }
  61. /**
  62. * Centralized method for easier change of the hashing sys
  63. *
  64. * @param skillId
  65. * The Skill Id
  66. * @param skillLevel
  67. * The Skill Level
  68. * @return The Skill hash number
  69. */
  70. public static int getSkillHashCode(int skillId, int skillLevel)
  71. {
  72. return skillId * 1021 + skillLevel;
  73. }
  74. public final L2Skill getInfo(final int skillId, final int level)
  75. {
  76. final L2Skill result = _skills.get(getSkillHashCode(skillId, level));
  77. if (result != null)
  78. return result;
  79. // skill/level not found, fix for transformation scripts
  80. final int maxLvl = _skillMaxLevel.get(skillId);
  81. // requested level too high
  82. if (maxLvl > 0 && level > maxLvl)
  83. return _skills.get(getSkillHashCode(skillId, maxLvl));
  84. return null;
  85. }
  86. public final int getMaxLevel(final int skillId)
  87. {
  88. return _skillMaxLevel.get(skillId);
  89. }
  90. /**
  91. * Returns an array with siege skills. If addNoble == true, will add also Advanced headquarters.
  92. */
  93. public L2Skill[] getSiegeSkills(boolean addNoble)
  94. {
  95. L2Skill[] temp = null;
  96. if (addNoble)
  97. {
  98. temp = new L2Skill[3];
  99. temp[2] = _skills.get(SkillTable.getSkillHashCode(326, 1));
  100. }
  101. else
  102. temp = new L2Skill[2];
  103. temp[0] = _skills.get(SkillTable.getSkillHashCode(246, 1));
  104. temp[1] = _skills.get(SkillTable.getSkillHashCode(247, 1));
  105. return temp;
  106. }
  107. @SuppressWarnings("synthetic-access")
  108. private static class SingletonHolder
  109. {
  110. protected static final SkillTable _instance = new SkillTable();
  111. }
  112. /**
  113. * Enum to hold some important references to frequently used (hardcoded) skills in core
  114. *
  115. * @author DrHouse
  116. *
  117. */
  118. public static enum FrequentSkill
  119. {
  120. RAID_CURSE(4215, 1),
  121. RAID_CURSE2(4515, 1),
  122. SEAL_OF_RULER(246, 1),
  123. BUILD_HEADQUARTERS(247, 1),
  124. LUCKY(194, 1),
  125. DWARVEN_CRAFT(1321, 1),
  126. COMMON_CRAFT(1322, 1),
  127. WYVERN_BREATH(4289, 1),
  128. STRIDER_SIEGE_ASSAULT(325, 1),
  129. FAKE_PETRIFICATION(4616, 1),
  130. FIREWORK(5965, 1),
  131. LARGE_FIREWORK(2025, 1),
  132. BLESSING_OF_PROTECTION(5182, 1),
  133. ARENA_CP_RECOVERY(4380, 1),
  134. VOID_BURST(3630, 1),
  135. VOID_FLOW(3631, 1),
  136. THE_VICTOR_OF_WAR(5074, 1),
  137. THE_VANQUISHED_OF_WAR(5075, 1),
  138. SPECIAL_TREE_RECOVERY_BONUS(2139, 1);
  139. private final int _id;
  140. private final int _level;
  141. private L2Skill _skill = null;
  142. private FrequentSkill(int id, int level)
  143. {
  144. _id = id;
  145. _level = level;
  146. }
  147. protected static void onReload()
  148. {
  149. for (FrequentSkill sk : FrequentSkill.values())
  150. sk.reload();
  151. }
  152. public L2Skill reload()
  153. {
  154. return (_skill = SkillTable.getInstance().getInfo(_id, _level));
  155. }
  156. public L2Skill getSkill()
  157. {
  158. return _skill;
  159. }
  160. }
  161. }