Fear.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.CtrlIntention;
  23. import com.l2jserver.gameserver.model.L2CharPosition;
  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. * Implementation of the Fear Effect
  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 L2EffectType getEffectType()
  50. {
  51. return L2EffectType.FEAR;
  52. }
  53. @Override
  54. public boolean onStart()
  55. {
  56. if ((getEffected() instanceof L2NpcInstance) || (getEffected() instanceof L2DefenderInstance) || (getEffected() instanceof L2FortCommanderInstance) || (getEffected() instanceof L2SiegeFlagInstance) || (getEffected() instanceof L2SiegeSummonInstance))
  57. {
  58. return false;
  59. }
  60. if (!getEffected().isAfraid())
  61. {
  62. if (getEffected().isCastingNow() && getEffected().canAbortCast())
  63. {
  64. getEffected().abortCast();
  65. }
  66. if (getEffected().getX() > getEffector().getX())
  67. {
  68. _dX = 1;
  69. }
  70. if (getEffected().getY() > getEffector().getY())
  71. {
  72. _dY = 1;
  73. }
  74. getEffected().startFear();
  75. onActionTime();
  76. return true;
  77. }
  78. return false;
  79. }
  80. @Override
  81. public void onExit()
  82. {
  83. getEffected().stopFear(false);
  84. }
  85. @Override
  86. public boolean onActionTime()
  87. {
  88. int posX = getEffected().getX();
  89. int posY = getEffected().getY();
  90. int posZ = getEffected().getZ();
  91. if (getEffected().getX() > getEffector().getX())
  92. {
  93. _dX = 1;
  94. }
  95. if (getEffected().getY() > getEffector().getY())
  96. {
  97. _dY = 1;
  98. }
  99. posX += _dX * FEAR_RANGE;
  100. posY += _dY * FEAR_RANGE;
  101. if (Config.GEODATA > 0)
  102. {
  103. Location destiny = GeoData.getInstance().moveCheck(getEffected().getX(), getEffected().getY(), getEffected().getZ(), posX, posY, posZ, getEffected().getInstanceId());
  104. posX = destiny.getX();
  105. posY = destiny.getY();
  106. }
  107. if (!getEffected().isPet())
  108. {
  109. getEffected().setRunning();
  110. }
  111. getEffected().getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  112. return true;
  113. }
  114. @Override
  115. public int getEffectFlags()
  116. {
  117. return EffectFlag.FEAR.getMask();
  118. }
  119. }