EffectFear.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 com.l2jserver.gameserver.skills.effects;
  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.L2Effect;
  22. import com.l2jserver.gameserver.model.Location;
  23. import com.l2jserver.gameserver.model.actor.instance.L2DefenderInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2FortCommanderInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  29. import com.l2jserver.gameserver.model.actor.instance.L2SiegeSummonInstance;
  30. import com.l2jserver.gameserver.skills.Env;
  31. import com.l2jserver.gameserver.templates.effects.EffectTemplate;
  32. import com.l2jserver.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 com.l2jserver.gameserver.model.L2Effect#getEffectType()
  50. */
  51. @Override
  52. public L2EffectType getEffectType()
  53. {
  54. return L2EffectType.FEAR;
  55. }
  56. /**
  57. *
  58. * @see com.l2jserver.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, Hell Scream and
  65. // Mass Curse Fear are the exceptions.
  66. if (getEffected() instanceof L2PcInstance
  67. && getEffector() instanceof L2PcInstance)
  68. {
  69. switch (getSkill().getId())
  70. {
  71. case 1376:
  72. case 1169:
  73. case 65:
  74. case 1092:
  75. case 98:
  76. case 1272:
  77. case 1381:
  78. case 763:
  79. break;
  80. default:
  81. return false;
  82. }
  83. }
  84. if (getEffected() instanceof L2NpcInstance
  85. || getEffected() instanceof L2DefenderInstance
  86. || getEffected() instanceof L2FortCommanderInstance
  87. || getEffected() instanceof L2SiegeFlagInstance
  88. || getEffected() instanceof L2SiegeSummonInstance)
  89. return false;
  90. if (!getEffected().isAfraid())
  91. {
  92. if(getEffected().isCastingNow() && getEffected().canAbortCast())
  93. getEffected().abortCast();
  94. if (getEffected().getX() > getEffector().getX())
  95. _dX = 1;
  96. if (getEffected().getY() > getEffector().getY())
  97. _dY = 1;
  98. getEffected().startFear();
  99. onActionTime();
  100. return true;
  101. }
  102. return false;
  103. }
  104. /**
  105. *
  106. * @see com.l2jserver.gameserver.model.L2Effect#onExit()
  107. */
  108. @Override
  109. public void onExit()
  110. {
  111. getEffected().stopFear(false);
  112. }
  113. /**
  114. *
  115. * @see com.l2jserver.gameserver.model.L2Effect#onActionTime()
  116. */
  117. @Override
  118. public boolean onActionTime()
  119. {
  120. int posX = getEffected().getX();
  121. int posY = getEffected().getY();
  122. int posZ = getEffected().getZ();
  123. if (getEffected().getX() > getEffector().getX())
  124. _dX = 1;
  125. if (getEffected().getY() > getEffector().getY())
  126. _dY = 1;
  127. posX += _dX * FEAR_RANGE;
  128. posY += _dY * FEAR_RANGE;
  129. if (Config.GEODATA > 0)
  130. {
  131. Location destiny = GeoData.getInstance().moveCheck(getEffected().getX(), getEffected().getY(), getEffected().getZ(), posX, posY, posZ, getEffected().getInstanceId());
  132. posX = destiny.getX();
  133. posY = destiny.getY();
  134. }
  135. if (!(getEffected() instanceof L2PetInstance))
  136. getEffected().setRunning();
  137. getEffected().getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  138. return true;
  139. }
  140. /* (non-Javadoc)
  141. * @see com.l2jserver.gameserver.model.L2Effect#getEffectFlags()
  142. */
  143. @Override
  144. public int getEffectFlags()
  145. {
  146. return CharEffectList.EFFECT_FLAG_FEAR;
  147. }
  148. }