Fear.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 handlers.effecthandlers;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.GeoData;
  18. import com.l2jserver.gameserver.ai.CtrlIntention;
  19. import com.l2jserver.gameserver.model.CharEffectList;
  20. import com.l2jserver.gameserver.model.L2CharPosition;
  21. import com.l2jserver.gameserver.model.Location;
  22. import com.l2jserver.gameserver.model.actor.instance.L2DefenderInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2FortCommanderInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2SiegeSummonInstance;
  28. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  29. import com.l2jserver.gameserver.model.effects.L2Effect;
  30. import com.l2jserver.gameserver.model.effects.L2EffectType;
  31. import com.l2jserver.gameserver.model.stats.Env;
  32. /**
  33. * Implementation of the Fear Effect
  34. * @author littlecrow
  35. */
  36. public class Fear extends L2Effect
  37. {
  38. public static final int FEAR_RANGE = 500;
  39. private int _dX = -1;
  40. private int _dY = -1;
  41. public Fear(Env env, EffectTemplate template)
  42. {
  43. super(env, template);
  44. }
  45. @Override
  46. public L2EffectType getEffectType()
  47. {
  48. return L2EffectType.FEAR;
  49. }
  50. @Override
  51. public boolean onStart()
  52. {
  53. if (getEffected() instanceof L2NpcInstance
  54. || getEffected() instanceof L2DefenderInstance
  55. || getEffected() instanceof L2FortCommanderInstance
  56. || getEffected() instanceof L2SiegeFlagInstance
  57. || getEffected() instanceof L2SiegeSummonInstance)
  58. return false;
  59. if (!getEffected().isAfraid())
  60. {
  61. if(getEffected().isCastingNow() && getEffected().canAbortCast())
  62. getEffected().abortCast();
  63. if (getEffected().getX() > getEffector().getX())
  64. _dX = 1;
  65. if (getEffected().getY() > getEffector().getY())
  66. _dY = 1;
  67. getEffected().startFear();
  68. onActionTime();
  69. return true;
  70. }
  71. return false;
  72. }
  73. @Override
  74. public void onExit()
  75. {
  76. getEffected().stopFear(false);
  77. }
  78. @Override
  79. public boolean onActionTime()
  80. {
  81. int posX = getEffected().getX();
  82. int posY = getEffected().getY();
  83. int posZ = getEffected().getZ();
  84. if (getEffected().getX() > getEffector().getX())
  85. _dX = 1;
  86. if (getEffected().getY() > getEffector().getY())
  87. _dY = 1;
  88. posX += _dX * FEAR_RANGE;
  89. posY += _dY * FEAR_RANGE;
  90. if (Config.GEODATA > 0)
  91. {
  92. Location destiny = GeoData.getInstance().moveCheck(getEffected().getX(), getEffected().getY(), getEffected().getZ(), posX, posY, posZ, getEffected().getInstanceId());
  93. posX = destiny.getX();
  94. posY = destiny.getY();
  95. }
  96. if (!(getEffected() instanceof L2PetInstance))
  97. getEffected().setRunning();
  98. getEffected().getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  99. return true;
  100. }
  101. @Override
  102. public int getEffectFlags()
  103. {
  104. return CharEffectList.EFFECT_FLAG_FEAR;
  105. }
  106. }