ChameleonRest.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  20. import com.l2jserver.gameserver.model.effects.L2Effect;
  21. import com.l2jserver.gameserver.model.effects.L2EffectType;
  22. import com.l2jserver.gameserver.model.skills.L2SkillType;
  23. import com.l2jserver.gameserver.model.stats.Env;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. public class ChameleonRest extends L2Effect
  26. {
  27. public ChameleonRest(Env env, EffectTemplate template)
  28. {
  29. super(env, template);
  30. }
  31. @Override
  32. public L2EffectType getEffectType()
  33. {
  34. return L2EffectType.RELAXING;
  35. }
  36. @Override
  37. public boolean onStart()
  38. {
  39. if (getEffected() instanceof L2PcInstance)
  40. {
  41. ((L2PcInstance) getEffected()).sitDown(false);
  42. }
  43. else
  44. getEffected().getAI().setIntention(CtrlIntention.AI_INTENTION_REST);
  45. return super.onStart();
  46. }
  47. @Override
  48. public void onExit()
  49. {
  50. super.onExit();
  51. }
  52. @Override
  53. public boolean onActionTime()
  54. {
  55. if (getEffected().isDead())
  56. return false;
  57. // Only cont skills shouldn't end
  58. if (getSkill().getSkillType() != L2SkillType.CONT)
  59. return false;
  60. if (getEffected() instanceof L2PcInstance)
  61. {
  62. if (!((L2PcInstance) getEffected()).isSitting())
  63. return false;
  64. }
  65. double manaDam = calc();
  66. if (manaDam > getEffected().getCurrentMp())
  67. {
  68. getEffected().sendPacket(SystemMessageId.SKILL_REMOVED_DUE_LACK_MP);
  69. return false;
  70. }
  71. getEffected().reduceCurrentMp(manaDam);
  72. return true;
  73. }
  74. @Override
  75. public int getEffectFlags()
  76. {
  77. return (CharEffectList.EFFECT_FLAG_SILENT_MOVE | CharEffectList.EFFECT_FLAG_RELAXING);
  78. }
  79. }