EffectChameleonRest.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 net.sf.l2j.gameserver.skills.effects;
  16. import net.sf.l2j.gameserver.ai.CtrlIntention;
  17. import net.sf.l2j.gameserver.model.L2Character;
  18. import net.sf.l2j.gameserver.model.L2Effect;
  19. import net.sf.l2j.gameserver.model.L2Skill.SkillType;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  21. import net.sf.l2j.gameserver.network.SystemMessageId;
  22. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  23. import net.sf.l2j.gameserver.skills.Env;
  24. class EffectChameleonRest extends L2Effect
  25. {
  26. public EffectChameleonRest(Env env, EffectTemplate template)
  27. {
  28. super(env, template);
  29. }
  30. @Override
  31. public EffectType getEffectType()
  32. {
  33. return EffectType.RELAXING;
  34. }
  35. /** Notify started */
  36. @Override
  37. public void onStart() {
  38. L2Character effected = getEffected();
  39. if(effected instanceof L2PcInstance)
  40. {
  41. setChameleon(true);
  42. ((L2PcInstance)effected).setSilentMoving(true);
  43. ((L2PcInstance)effected).sitDown();
  44. }
  45. else
  46. effected.getAI().setIntention(CtrlIntention.AI_INTENTION_REST);
  47. super.onStart();
  48. }
  49. /* (non-Javadoc)
  50. * @see net.sf.l2j.gameserver.model.L2Effect#onExit()
  51. */
  52. @Override
  53. public void onExit() {
  54. setChameleon(false);
  55. L2Character effected = getEffected();
  56. if (effected instanceof L2PcInstance)
  57. ((L2PcInstance)effected).setSilentMoving(false);
  58. super.onExit();
  59. }
  60. @Override
  61. public boolean onActionTime()
  62. {
  63. L2Character effected = getEffected();
  64. boolean retval = true;
  65. if(effected.isDead())
  66. retval = false;
  67. // Only cont skills shouldn't end
  68. if(getSkill().getSkillType() != SkillType.CONT)
  69. return false;
  70. if(effected instanceof L2PcInstance)
  71. {
  72. if(!((L2PcInstance)effected).isSitting())
  73. retval = false;
  74. }
  75. double manaDam = calc();
  76. if(manaDam > effected.getCurrentMp())
  77. {
  78. SystemMessage sm = new SystemMessage(SystemMessageId.SKILL_REMOVED_DUE_LACK_MP);
  79. effected.sendPacket(sm);
  80. return false;
  81. }
  82. if (!retval)
  83. setChameleon(retval);
  84. else
  85. effected.reduceCurrentMp(manaDam);
  86. return retval;
  87. }
  88. private void setChameleon(boolean val)
  89. {
  90. L2Character effected = getEffected();
  91. if(effected instanceof L2PcInstance)
  92. ((L2PcInstance)effected).setRelax(val);
  93. }
  94. }