Fear.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.effecthandlers;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.GeoData;
  22. import com.l2jserver.gameserver.ai.CtrlEvent;
  23. import com.l2jserver.gameserver.ai.CtrlIntention;
  24. import com.l2jserver.gameserver.model.Location;
  25. import com.l2jserver.gameserver.model.actor.instance.L2DefenderInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2FortCommanderInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  29. import com.l2jserver.gameserver.model.actor.instance.L2SiegeSummonInstance;
  30. import com.l2jserver.gameserver.model.effects.EffectFlag;
  31. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  32. import com.l2jserver.gameserver.model.effects.L2Effect;
  33. import com.l2jserver.gameserver.model.effects.L2EffectType;
  34. import com.l2jserver.gameserver.model.stats.Env;
  35. /**
  36. * Fear effect implementation.
  37. * @author littlecrow
  38. */
  39. public class Fear extends L2Effect
  40. {
  41. public static final int FEAR_RANGE = 500;
  42. private int _dX = -1;
  43. private int _dY = -1;
  44. public Fear(Env env, EffectTemplate template)
  45. {
  46. super(env, template);
  47. }
  48. @Override
  49. public int getEffectFlags()
  50. {
  51. return EffectFlag.FEAR.getMask();
  52. }
  53. @Override
  54. public L2EffectType getEffectType()
  55. {
  56. return L2EffectType.FEAR;
  57. }
  58. @Override
  59. public boolean onActionTime()
  60. {
  61. int posX = getEffected().getX();
  62. int posY = getEffected().getY();
  63. int posZ = getEffected().getZ();
  64. if (getEffected().getX() > getEffector().getX())
  65. {
  66. _dX = 1;
  67. }
  68. if (getEffected().getY() > getEffector().getY())
  69. {
  70. _dY = 1;
  71. }
  72. posX += _dX * FEAR_RANGE;
  73. posY += _dY * FEAR_RANGE;
  74. if (Config.GEODATA > 0)
  75. {
  76. Location destiny = GeoData.getInstance().moveCheck(getEffected().getX(), getEffected().getY(), getEffected().getZ(), posX, posY, posZ, getEffected().getInstanceId());
  77. posX = destiny.getX();
  78. posY = destiny.getY();
  79. }
  80. if (!getEffected().isPet())
  81. {
  82. getEffected().setRunning();
  83. }
  84. getEffected().getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(posX, posY, posZ));
  85. return false;
  86. }
  87. @Override
  88. public boolean onStart()
  89. {
  90. if ((getEffected() instanceof L2NpcInstance) || (getEffected() instanceof L2DefenderInstance) || (getEffected() instanceof L2FortCommanderInstance) || (getEffected() instanceof L2SiegeFlagInstance) || (getEffected() instanceof L2SiegeSummonInstance))
  91. {
  92. return false;
  93. }
  94. if (getEffected().isAfraid())
  95. {
  96. return false;
  97. }
  98. if (getEffected().isCastingNow() && getEffected().canAbortCast())
  99. {
  100. getEffected().abortCast();
  101. }
  102. if (getEffected().getX() > getEffector().getX())
  103. {
  104. _dX = 1;
  105. }
  106. if (getEffected().getY() > getEffector().getY())
  107. {
  108. _dY = 1;
  109. }
  110. getEffected().getAI().notifyEvent(CtrlEvent.EVT_AFRAID);
  111. onActionTime();
  112. return super.onStart();
  113. }
  114. }