EffectFear.java 3.8 KB

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