SkillTable.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. import net.sf.l2j.gameserver.templates.L2WeaponType;
  22. /**
  23. * This class ...
  24. *
  25. * @version $Revision: 1.8.2.6.2.18 $ $Date: 2005/04/06 16:13:25 $
  26. */
  27. public class SkillTable
  28. {
  29. //private static Logger _log = Logger.getLogger(SkillTable.class.getName());
  30. private static SkillTable _instance;
  31. private Map<Integer, L2Skill> _skills;
  32. private boolean _initialized = true;
  33. public static SkillTable getInstance()
  34. {
  35. if (_instance == null)
  36. _instance = new SkillTable();
  37. return _instance;
  38. }
  39. private SkillTable()
  40. {
  41. _skills = new FastMap<Integer, L2Skill>();
  42. SkillsEngine.getInstance().loadAllSkills(_skills);
  43. }
  44. public void reload()
  45. {
  46. _instance = new SkillTable();
  47. }
  48. public boolean isInitialized()
  49. {
  50. return _initialized;
  51. }
  52. /**
  53. * Provides the skill hash
  54. * @param skill The L2Skill to be hashed
  55. * @return SkillTable.getSkillHashCode(skill.getId(), skill.getLevel())
  56. */
  57. public static int getSkillHashCode(L2Skill skill)
  58. {
  59. return SkillTable.getSkillHashCode(skill.getId(), skill.getLevel());
  60. }
  61. /**
  62. * Centralized method for easier change of the hashing sys
  63. * @param skillId The Skill Id
  64. * @param skillLevel The Skill Level
  65. * @return The Skill hash number
  66. */
  67. public static int getSkillHashCode(int skillId, int skillLevel)
  68. {
  69. return skillId * 256 + skillLevel;
  70. }
  71. public L2Skill getInfo(int skillId, int level)
  72. {
  73. return _skills.get(SkillTable.getSkillHashCode(skillId, level));
  74. }
  75. public int getMaxLevel(int magicId, int level)
  76. {
  77. L2Skill temp;
  78. while (level < 100)
  79. {
  80. level++;
  81. temp = _skills.get(SkillTable.getSkillHashCode(magicId, level));
  82. if (temp == null)
  83. return level - 1;
  84. }
  85. return level;
  86. }
  87. private static final L2WeaponType[] weaponDbMasks =
  88. {
  89. L2WeaponType.ETC, L2WeaponType.BOW, L2WeaponType.POLE, L2WeaponType.DUALFIST, L2WeaponType.DUAL, L2WeaponType.BLUNT, L2WeaponType.SWORD, L2WeaponType.DAGGER, L2WeaponType.BIGSWORD, L2WeaponType.ROD, L2WeaponType.BIGBLUNT,
  90. L2WeaponType.ANCIENT_SWORD, L2WeaponType.RAPIER, L2WeaponType.CROSSBOW
  91. };
  92. public int calcWeaponsAllowed(int mask)
  93. {
  94. if (mask == 0)
  95. return 0;
  96. int weaponsAllowed = 0;
  97. for (int i = 0; i < weaponDbMasks.length; i++)
  98. if ((mask & (1 << i)) != 0)
  99. weaponsAllowed |= weaponDbMasks[i].mask();
  100. return weaponsAllowed;
  101. }
  102. /**
  103. * Returns an array with siege skills. If addNoble == true, will add also Advanced headquarters.
  104. */
  105. public L2Skill[] getSiegeSkills(boolean addNoble)
  106. {
  107. FastList<L2Skill> list = new FastList<L2Skill>();
  108. list.add(_skills.get(SkillTable.getSkillHashCode(246, 1)));
  109. list.add(_skills.get(SkillTable.getSkillHashCode(247, 1)));
  110. if (addNoble)
  111. list.add(_skills.get(SkillTable.getSkillHashCode(326, 1)));
  112. L2Skill[] temp = new L2Skill[list.size()];
  113. list.toArray(temp);
  114. return temp;
  115. }
  116. }