EffectFear.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.L2CharPosition;
  18. import net.sf.l2j.gameserver.model.L2Effect;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2FolkInstance;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2SiegeFlagInstance;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2SiegeGuardInstance;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2SiegeSummonInstance;
  24. import net.sf.l2j.gameserver.skills.Env;
  25. /**
  26. * @author littlecrow
  27. *
  28. * Implementation of the Fear Effect
  29. */
  30. final class EffectFear extends L2Effect
  31. {
  32. public static final int FEAR_RANGE = 500;
  33. private int _dX = -1;
  34. private int _dY = -1;
  35. public EffectFear(Env env, EffectTemplate template)
  36. {
  37. super(env, template);
  38. }
  39. /**
  40. *
  41. * @see net.sf.l2j.gameserver.model.L2Effect#getEffectType()
  42. */
  43. @Override
  44. public EffectType getEffectType()
  45. {
  46. return EffectType.FEAR;
  47. }
  48. /**
  49. *
  50. * @see net.sf.l2j.gameserver.model.L2Effect#onStart()
  51. */
  52. @Override
  53. public void onStart()
  54. {
  55. // Fear skills cannot be used l2pcinstance to l2pcinstance. Heroic
  56. // Dread, Curse: Fear, Fear, Horror, Sword Symphony, Word of Fear and
  57. // Mass Curse Fear are the exceptions.
  58. if (getEffected() instanceof L2PcInstance
  59. && getEffector() instanceof L2PcInstance
  60. && getSkill().getId() != 1376 && getSkill().getId() != 1169
  61. && getSkill().getId() != 65 && getSkill().getId() != 1092
  62. && getSkill().getId() != 98 && getSkill().getId() != 1272
  63. && getSkill().getId() != 1381)
  64. return;
  65. if (getEffected() instanceof L2FolkInstance
  66. || getEffected() instanceof L2SiegeGuardInstance
  67. || getEffected() instanceof L2SiegeFlagInstance
  68. || getEffected() instanceof L2SiegeSummonInstance)
  69. return;
  70. if (!getEffected().isAfraid())
  71. {
  72. if (getEffected().getX() > getEffector().getX())
  73. _dX = 1;
  74. if (getEffected().getY() > getEffector().getY())
  75. _dY = 1;
  76. getEffected().startFear();
  77. onActionTime();
  78. }
  79. }
  80. /**
  81. *
  82. * @see net.sf.l2j.gameserver.model.L2Effect#onExit()
  83. */
  84. @Override
  85. public void onExit()
  86. {
  87. getEffected().stopFear(this);
  88. }
  89. /**
  90. *
  91. * @see net.sf.l2j.gameserver.model.L2Effect#onActionTime()
  92. */
  93. @Override
  94. public boolean onActionTime()
  95. {
  96. int posX = getEffected().getX();
  97. int posY = getEffected().getY();
  98. int posZ = getEffected().getZ();
  99. posX += _dX * FEAR_RANGE;
  100. posY += _dY * FEAR_RANGE;
  101. getEffected().setRunning();
  102. getEffected().getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  103. return true;
  104. }
  105. }