L2SkillChargeEffect.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.skills.l2skills;
  16. import net.sf.l2j.gameserver.model.L2Object;
  17. import net.sf.l2j.gameserver.model.L2Skill;
  18. import net.sf.l2j.gameserver.model.actor.L2Character;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.network.SystemMessageId;
  21. import net.sf.l2j.gameserver.network.serverpackets.EtcStatusUpdate;
  22. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  23. import net.sf.l2j.gameserver.skills.effects.EffectCharge;
  24. import net.sf.l2j.gameserver.templates.StatsSet;
  25. public class L2SkillChargeEffect extends L2Skill
  26. {
  27. final int chargeSkillId;
  28. public L2SkillChargeEffect(StatsSet set)
  29. {
  30. super(set);
  31. chargeSkillId = set.getInteger("charge_skill_id");
  32. }
  33. @Override
  34. public boolean checkCondition(L2Character activeChar, L2Object target, boolean itemOrWeapon)
  35. {
  36. if (activeChar instanceof L2PcInstance)
  37. {
  38. L2PcInstance player = (L2PcInstance)activeChar;
  39. EffectCharge e = (EffectCharge)player.getFirstEffect(chargeSkillId);
  40. if(e == null || e.numCharges < getNumCharges())
  41. {
  42. SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  43. sm.addSkillName(this);
  44. activeChar.sendPacket(sm);
  45. return false;
  46. }
  47. }
  48. return super.checkCondition(activeChar, target, itemOrWeapon);
  49. }
  50. @Override
  51. public void useSkill(L2Character activeChar, L2Object[] targets)
  52. {
  53. if (activeChar.isAlikeDead()) return;
  54. // get the effect
  55. EffectCharge effect = (EffectCharge)activeChar.getFirstEffect(chargeSkillId);
  56. if (effect == null || effect.numCharges < getNumCharges())
  57. {
  58. SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  59. sm.addSkillName(this);
  60. activeChar.sendPacket(sm);
  61. return;
  62. }
  63. // decrease?
  64. effect.numCharges -= getNumCharges();
  65. // update icons
  66. // activeChar.updateEffectIcons();
  67. // maybe exit? no charge
  68. if (effect.numCharges == 0) effect.exit();
  69. // apply effects
  70. if (hasEffects())
  71. for (L2Character target: (L2Character[]) targets)
  72. getEffects(activeChar, target);
  73. if (activeChar instanceof L2PcInstance)
  74. {
  75. activeChar.sendPacket(new EtcStatusUpdate((L2PcInstance)activeChar));
  76. }
  77. }
  78. }