SkillTable.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.FastMap;
  18. import net.sf.l2j.gameserver.model.L2Skill;
  19. import net.sf.l2j.gameserver.skills.SkillsEngine;
  20. import net.sf.l2j.gameserver.templates.L2WeaponType;
  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 SkillTable _instance;
  30. private Map<Integer, L2Skill> _skills;
  31. private boolean _initialized = true;
  32. public static SkillTable getInstance()
  33. {
  34. if (_instance == null)
  35. _instance = new SkillTable();
  36. return _instance;
  37. }
  38. private SkillTable()
  39. {
  40. _skills = new FastMap<Integer, L2Skill>();
  41. SkillsEngine.getInstance().loadAllSkills(_skills);
  42. }
  43. public void reload()
  44. {
  45. _instance = new SkillTable();
  46. }
  47. public boolean isInitialized()
  48. {
  49. return _initialized;
  50. }
  51. /**
  52. * Provides the skill hash
  53. * @param skill The L2Skill to be hashed
  54. * @return SkillTable.getSkillHashCode(skill.getId(), skill.getLevel())
  55. */
  56. public static int getSkillHashCode(L2Skill skill)
  57. {
  58. return SkillTable.getSkillHashCode(skill.getId(), skill.getLevel());
  59. }
  60. /**
  61. * Centralized method for easier change of the hashing sys
  62. * @param skillId The Skill Id
  63. * @param skillLevel The Skill Level
  64. * @return The Skill hash number
  65. */
  66. public static int getSkillHashCode(int skillId, int skillLevel)
  67. {
  68. return skillId*256+skillLevel;
  69. }
  70. public L2Skill getInfo(int skillId, int level)
  71. {
  72. return _skills.get(SkillTable.getSkillHashCode(skillId, level));
  73. }
  74. public int getMaxLevel(int magicId, int level)
  75. {
  76. L2Skill temp;
  77. while (level < 100)
  78. {
  79. level++;
  80. temp = _skills.get(SkillTable.getSkillHashCode(magicId, level));
  81. if (temp == null)
  82. return level-1;
  83. }
  84. return level;
  85. }
  86. private static final L2WeaponType[] weaponDbMasks = {
  87. L2WeaponType.ETC,
  88. L2WeaponType.BOW,
  89. L2WeaponType.POLE,
  90. L2WeaponType.DUALFIST,
  91. L2WeaponType.DUAL,
  92. L2WeaponType.BLUNT,
  93. L2WeaponType.SWORD,
  94. L2WeaponType.DAGGER,
  95. L2WeaponType.BIGSWORD,
  96. L2WeaponType.ROD,
  97. L2WeaponType.BIGBLUNT,
  98. L2WeaponType.ANCIENT_SWORD,
  99. L2WeaponType.RAPIER,
  100. L2WeaponType.CROSSBOW
  101. };
  102. public int calcWeaponsAllowed(int mask)
  103. {
  104. if (mask == 0)
  105. return 0;
  106. int weaponsAllowed = 0;
  107. for (int i=0; i < weaponDbMasks.length; i++)
  108. if ((mask & (1<<i)) != 0)
  109. weaponsAllowed |= weaponDbMasks[i].mask();
  110. return weaponsAllowed;
  111. }
  112. }