EffectFear.java 4.0 KB

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