PlayerSkillHolder.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model.holders;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import com.l2jserver.gameserver.datatables.SkillTreesData;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.interfaces.ISkillsHolder;
  25. import com.l2jserver.gameserver.model.skills.Skill;
  26. /**
  27. * @author UnAfraid
  28. */
  29. public class PlayerSkillHolder implements ISkillsHolder
  30. {
  31. private final Map<Integer, Skill> _skills = new HashMap<>();
  32. public PlayerSkillHolder(L2PcInstance player)
  33. {
  34. for (Skill skill : player.getSkills().values())
  35. {
  36. // Adding only skills that can be learned by the player.
  37. if (SkillTreesData.getInstance().isSkillAllowed(player, skill))
  38. {
  39. addSkill(skill);
  40. }
  41. }
  42. }
  43. /**
  44. * @return the map containing this character skills.
  45. */
  46. @Override
  47. public Map<Integer, Skill> getSkills()
  48. {
  49. return _skills;
  50. }
  51. /**
  52. * Add a skill to the skills map.<br>
  53. * @param skill
  54. */
  55. @Override
  56. public Skill addSkill(Skill skill)
  57. {
  58. return _skills.put(skill.getId(), skill);
  59. }
  60. /**
  61. * Return the level of a skill owned by the L2Character.
  62. * @param skillId The identifier of the L2Skill whose level must be returned
  63. * @return The level of the L2Skill identified by skillId
  64. */
  65. @Override
  66. public int getSkillLevel(int skillId)
  67. {
  68. final Skill skill = getKnownSkill(skillId);
  69. return (skill == null) ? -1 : skill.getLevel();
  70. }
  71. /**
  72. * @param skillId The identifier of the L2Skill to check the knowledge
  73. * @return the skill from the known skill.
  74. */
  75. @Override
  76. public Skill getKnownSkill(int skillId)
  77. {
  78. return _skills.get(skillId);
  79. }
  80. }