EffectFear.java 4.4 KB

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