SoulEating.java 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2004-2014 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 handlers.effecthandlers;
  20. import com.l2jserver.gameserver.model.StatsSet;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.L2Playable;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.conditions.Condition;
  25. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  26. import com.l2jserver.gameserver.model.events.EventType;
  27. import com.l2jserver.gameserver.model.events.listeners.AbstractEventListener;
  28. import com.l2jserver.gameserver.model.skills.BuffInfo;
  29. import com.l2jserver.gameserver.model.stats.Stats;
  30. import com.l2jserver.gameserver.network.SystemMessageId;
  31. import com.l2jserver.gameserver.network.serverpackets.ExSpawnEmitter;
  32. /**
  33. * Soul Eating effect implementation.
  34. * @author UnAfraid
  35. */
  36. public final class SoulEating extends AbstractEffect
  37. {
  38. private final int _expNeeded;
  39. public SoulEating(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  40. {
  41. super(attachCond, applyCond, set, params);
  42. _expNeeded = params.getInt("expNeeded");
  43. }
  44. @Override
  45. public void onExit(BuffInfo info)
  46. {
  47. if (info.getEffected().isPlayer())
  48. {
  49. info.getEffected().getListeners(EventType.ON_PLAYABLE_EXP_CHANGED).stream().filter(listener -> listener.getOwner() == this).forEach(AbstractEventListener::unregisterMe);
  50. }
  51. }
  52. public void onExperienceReceived(L2Playable playable, long exp)
  53. {
  54. // TODO: Verify logic.
  55. if (playable.isPlayer() && (exp >= _expNeeded))
  56. {
  57. final L2PcInstance player = playable.getActingPlayer();
  58. final int maxSouls = (int) player.calcStat(Stats.MAX_SOULS, 0, null, null);
  59. if (player.getChargedSouls() >= maxSouls)
  60. {
  61. playable.sendPacket(SystemMessageId.SOUL_CANNOT_BE_ABSORBED_ANYMORE);
  62. return;
  63. }
  64. player.increaseSouls(1);
  65. if ((player.getTarget() != null) && player.getTarget().isNpc())
  66. {
  67. final L2Npc npc = (L2Npc) playable.getTarget();
  68. player.broadcastPacket(new ExSpawnEmitter(player, npc), 500);
  69. }
  70. }
  71. }
  72. @Override
  73. public void onStart(BuffInfo info)
  74. {
  75. if (info.getEffected().isPlayer())
  76. {
  77. info.getEffected().removeListenerIf(EventType.ON_PLAYABLE_EXP_CHANGED, listener -> listener.getOwner() == this);
  78. }
  79. }
  80. }