EffectChameleonRest.java 3.3 KB

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