Relax.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 handlers.effecthandlers;
  16. import com.l2jserver.gameserver.ai.CtrlIntention;
  17. import com.l2jserver.gameserver.model.CharEffectList;
  18. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  19. import com.l2jserver.gameserver.model.effects.L2Effect;
  20. import com.l2jserver.gameserver.model.effects.L2EffectType;
  21. import com.l2jserver.gameserver.model.stats.Env;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. public class Relax extends L2Effect
  24. {
  25. public Relax(Env env, EffectTemplate template)
  26. {
  27. super(env, template);
  28. }
  29. @Override
  30. public L2EffectType getEffectType()
  31. {
  32. return L2EffectType.RELAXING;
  33. }
  34. @Override
  35. public boolean onStart()
  36. {
  37. if (getEffected().isPlayer())
  38. {
  39. getEffected().getActingPlayer().sitDown(false);
  40. }
  41. else
  42. getEffected().getAI().setIntention(CtrlIntention.AI_INTENTION_REST);
  43. return super.onStart();
  44. }
  45. @Override
  46. public void onExit()
  47. {
  48. super.onExit();
  49. }
  50. @Override
  51. public boolean onActionTime()
  52. {
  53. if (getEffected().isDead())
  54. return false;
  55. if (getEffected().isPlayer())
  56. {
  57. if (!getEffected().getActingPlayer().isSitting())
  58. return false;
  59. }
  60. if (getEffected().getCurrentHp() + 1 > getEffected().getMaxRecoverableHp())
  61. {
  62. if (getSkill().isToggle())
  63. {
  64. getEffected().sendPacket(SystemMessageId.SKILL_DEACTIVATED_HP_FULL);
  65. return false;
  66. }
  67. }
  68. double manaDam = calc();
  69. if (manaDam > getEffected().getCurrentMp())
  70. {
  71. if (getSkill().isToggle())
  72. {
  73. getEffected().sendPacket(SystemMessageId.SKILL_REMOVED_DUE_LACK_MP);
  74. return false;
  75. }
  76. }
  77. getEffected().reduceCurrentMp(manaDam);
  78. return true;
  79. }
  80. @Override
  81. public int getEffectFlags()
  82. {
  83. return CharEffectList.EFFECT_FLAG_RELAXING;
  84. }
  85. }