SoulEating.java 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2004-2015 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.impl.character.playable.OnPlayableExpChanged;
  28. import com.l2jserver.gameserver.model.events.listeners.ConsumerEventListener;
  29. import com.l2jserver.gameserver.model.skills.BuffInfo;
  30. import com.l2jserver.gameserver.model.stats.Stats;
  31. import com.l2jserver.gameserver.network.SystemMessageId;
  32. import com.l2jserver.gameserver.network.serverpackets.ExSpawnEmitter;
  33. /**
  34. * Soul Eating effect implementation.
  35. * @author UnAfraid
  36. */
  37. public final class SoulEating extends AbstractEffect
  38. {
  39. private final int _expNeeded;
  40. public SoulEating(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  41. {
  42. super(attachCond, applyCond, set, params);
  43. _expNeeded = params.getInt("expNeeded");
  44. }
  45. @Override
  46. public void onExit(BuffInfo info)
  47. {
  48. if (info.getEffected().isPlayer())
  49. {
  50. info.getEffected().removeListenerIf(EventType.ON_PLAYABLE_EXP_CHANGED, listener -> listener.getOwner() == this);
  51. }
  52. }
  53. public void onExperienceReceived(L2Playable playable, long exp)
  54. {
  55. // TODO: Verify logic.
  56. if (playable.isPlayer() && (exp >= _expNeeded))
  57. {
  58. final L2PcInstance player = playable.getActingPlayer();
  59. final int maxSouls = (int) player.calcStat(Stats.MAX_SOULS, 0, null, null);
  60. if (player.getChargedSouls() >= maxSouls)
  61. {
  62. playable.sendPacket(SystemMessageId.SOUL_CANNOT_BE_ABSORBED_ANYMORE);
  63. return;
  64. }
  65. player.increaseSouls(1);
  66. if ((player.getTarget() != null) && player.getTarget().isNpc())
  67. {
  68. final L2Npc npc = (L2Npc) playable.getTarget();
  69. player.broadcastPacket(new ExSpawnEmitter(player, npc), 500);
  70. }
  71. }
  72. }
  73. @Override
  74. public void onStart(BuffInfo info)
  75. {
  76. if (info.getEffected().isPlayer())
  77. {
  78. info.getEffected().addListener(new ConsumerEventListener(info.getEffected(), EventType.ON_PLAYABLE_EXP_CHANGED, (OnPlayableExpChanged event) -> onExperienceReceived(event.getActiveChar(), (event.getNewExp() - event.getOldExp())), this));
  79. }
  80. }
  81. }