SoulEating.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2004-2013 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.actor.L2Npc;
  21. import com.l2jserver.gameserver.model.actor.L2Playable;
  22. import com.l2jserver.gameserver.model.actor.events.listeners.IExperienceReceivedEventListener;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  25. import com.l2jserver.gameserver.model.effects.L2Effect;
  26. import com.l2jserver.gameserver.model.effects.L2EffectType;
  27. import com.l2jserver.gameserver.model.stats.Env;
  28. import com.l2jserver.gameserver.model.stats.Stats;
  29. import com.l2jserver.gameserver.network.SystemMessageId;
  30. import com.l2jserver.gameserver.network.serverpackets.ExSpawnEmitter;
  31. /**
  32. * Soul Eating effect implementation.
  33. * @author UnAfraid
  34. */
  35. public final class SoulEating extends L2Effect implements IExperienceReceivedEventListener
  36. {
  37. private final int _expNeeded;
  38. public SoulEating(Env env, EffectTemplate template)
  39. {
  40. super(env, template);
  41. _expNeeded = template.getParameters().getInt("expNeeded");
  42. }
  43. public SoulEating(Env env, L2Effect effect)
  44. {
  45. super(env, effect);
  46. _expNeeded = effect.getEffectTemplate().getParameters().getInt("expNeeded");
  47. }
  48. @Override
  49. public L2EffectType getEffectType()
  50. {
  51. return L2EffectType.NONE;
  52. }
  53. @Override
  54. public boolean onExperienceReceived(L2Playable playable, long exp)
  55. {
  56. final L2PcInstance player = getEffected().isPlayer() ? getEffected().getActingPlayer() : null;
  57. if ((player != null) && (exp >= _expNeeded))
  58. {
  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 true;
  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. return true;
  73. }
  74. @Override
  75. public void onExit()
  76. {
  77. if (getEffected().isPlayer())
  78. {
  79. getEffected().getEvents().unregisterListener(this);
  80. }
  81. super.onExit();
  82. }
  83. @Override
  84. public boolean onStart()
  85. {
  86. if (getEffected().isPlayer())
  87. {
  88. getEffected().getEvents().registerListener(this);
  89. }
  90. return super.onStart();
  91. }
  92. }