Fear.java 3.7 KB

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