SkillTable.java 4.6 KB

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