L2SkillLearnSkill.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 com.l2jserver.gameserver.skills.l2skills;
  16. import com.l2jserver.gameserver.datatables.SkillTable;
  17. import com.l2jserver.gameserver.model.L2Object;
  18. import com.l2jserver.gameserver.model.L2Skill;
  19. import com.l2jserver.gameserver.model.StatsSet;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. public class L2SkillLearnSkill extends L2Skill
  23. {
  24. private final int[] _learnSkillId;
  25. private final int[] _learnSkillLvl;
  26. public L2SkillLearnSkill(StatsSet set)
  27. {
  28. super(set);
  29. String[] ar = set.getString("learnSkillId", "0").split(",");
  30. int[] ar2 = new int[ar.length];
  31. for (int i = 0; i < ar.length; i++)
  32. ar2[i] = Integer.parseInt(ar[i]);
  33. _learnSkillId = ar2;
  34. ar = set.getString("learnSkillLvl", "1").split(",");
  35. ar2 = new int[_learnSkillId.length];
  36. for (int i = 0; i < _learnSkillId.length; i++)
  37. ar2[i] = 1;
  38. for (int i = 0; i < ar.length; i++)
  39. ar2[i] = Integer.parseInt(ar[i]);
  40. _learnSkillLvl = ar2;
  41. }
  42. @Override
  43. public void useSkill(L2Character activeChar, L2Object[] targets)
  44. {
  45. if (!(activeChar instanceof L2PcInstance))
  46. return;
  47. final L2PcInstance player = ((L2PcInstance)activeChar);
  48. L2Skill newSkill;
  49. for (int i = 0; i < _learnSkillId.length; i++)
  50. {
  51. if (player.getSkillLevel(_learnSkillId[i]) < _learnSkillLvl[i] && _learnSkillId[i] != 0)
  52. {
  53. newSkill = SkillTable.getInstance().getInfo(_learnSkillId[i], _learnSkillLvl[i]);
  54. if (newSkill != null)
  55. player.addSkill(newSkill, true);
  56. }
  57. }
  58. }
  59. }