PlayerSkillHolder.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2004-2013 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.model.interfaces.ISkillsHolder;
  23. import com.l2jserver.gameserver.model.skills.L2Skill;
  24. /**
  25. * @author UnAfraid
  26. */
  27. public class PlayerSkillHolder implements ISkillsHolder
  28. {
  29. private final Map<Integer, L2Skill> _skills = new HashMap<>();
  30. public PlayerSkillHolder(Map<Integer, L2Skill> map)
  31. {
  32. _skills.putAll(map);
  33. }
  34. /**
  35. * @return the map containing this character skills.
  36. */
  37. @Override
  38. public Map<Integer, L2Skill> getSkills()
  39. {
  40. return _skills;
  41. }
  42. /**
  43. * Add a skill to the skills map.<br>
  44. * @param skill
  45. */
  46. @Override
  47. public L2Skill addSkill(L2Skill skill)
  48. {
  49. return _skills.put(skill.getId(), skill);
  50. }
  51. /**
  52. * Return the level of a skill owned by the L2Character.
  53. * @param skillId The identifier of the L2Skill whose level must be returned
  54. * @return The level of the L2Skill identified by skillId
  55. */
  56. @Override
  57. public int getSkillLevel(int skillId)
  58. {
  59. final L2Skill skill = getKnownSkill(skillId);
  60. return (skill == null) ? -1 : skill.getLevel();
  61. }
  62. /**
  63. * @param skillId The identifier of the L2Skill to check the knowledge
  64. * @return the skill from the known skill.
  65. */
  66. @Override
  67. public L2Skill getKnownSkill(int skillId)
  68. {
  69. return _skills.get(skillId);
  70. }
  71. }