SkillTable.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.item.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(getSkillHashCode(skillId, level));
  74. }
  75. public int getMaxLevel(int magicId, int level)
  76. {
  77. while (level < 100)
  78. {
  79. if (_skills.get(getSkillHashCode(magicId, ++level)) == null)
  80. return level - 1;
  81. }
  82. return level;
  83. }
  84. private static final L2WeaponType[] weaponDbMasks =
  85. {
  86. L2WeaponType.ETC, L2WeaponType.BOW, L2WeaponType.POLE, L2WeaponType.DUALFIST, L2WeaponType.DUAL, L2WeaponType.BLUNT, L2WeaponType.SWORD, L2WeaponType.DAGGER, L2WeaponType.BIGSWORD, L2WeaponType.ROD, L2WeaponType.BIGBLUNT,
  87. L2WeaponType.ANCIENT_SWORD, L2WeaponType.RAPIER, L2WeaponType.CROSSBOW
  88. };
  89. public int calcWeaponsAllowed(int mask)
  90. {
  91. if (mask == 0)
  92. return 0;
  93. int weaponsAllowed = 0;
  94. for (int i = 0; i < weaponDbMasks.length; i++)
  95. if ((mask & (1 << i)) != 0)
  96. weaponsAllowed |= weaponDbMasks[i].mask();
  97. return weaponsAllowed;
  98. }
  99. /**
  100. * Returns an array with siege skills. If addNoble == true, will add also Advanced headquarters.
  101. */
  102. public L2Skill[] getSiegeSkills(boolean addNoble)
  103. {
  104. FastList<L2Skill> list = new FastList<L2Skill>();
  105. list.add(_skills.get(SkillTable.getSkillHashCode(246, 1)));
  106. list.add(_skills.get(SkillTable.getSkillHashCode(247, 1)));
  107. if (addNoble)
  108. list.add(_skills.get(SkillTable.getSkillHashCode(326, 1)));
  109. L2Skill[] temp = new L2Skill[list.size()];
  110. list.toArray(temp);
  111. return temp;
  112. }
  113. }