EffectFear.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.L2CharPosition;
  20. import com.l2jserver.gameserver.model.L2Effect;
  21. import com.l2jserver.gameserver.model.Location;
  22. import com.l2jserver.gameserver.model.actor.instance.L2FortCommanderInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2DefenderInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2SiegeSummonInstance;
  29. import com.l2jserver.gameserver.skills.Env;
  30. import com.l2jserver.gameserver.templates.effects.EffectTemplate;
  31. import com.l2jserver.gameserver.templates.skills.L2EffectType;
  32. /**
  33. * @author littlecrow
  34. *
  35. * Implementation of the Fear Effect
  36. */
  37. public class EffectFear extends L2Effect
  38. {
  39. public static final int FEAR_RANGE = 500;
  40. private int _dX = -1;
  41. private int _dY = -1;
  42. public EffectFear(Env env, EffectTemplate template)
  43. {
  44. super(env, template);
  45. }
  46. /**
  47. *
  48. * @see com.l2jserver.gameserver.model.L2Effect#getEffectType()
  49. */
  50. @Override
  51. public L2EffectType getEffectType()
  52. {
  53. return L2EffectType.FEAR;
  54. }
  55. /**
  56. *
  57. * @see com.l2jserver.gameserver.model.L2Effect#onStart()
  58. */
  59. @Override
  60. public boolean onStart()
  61. {
  62. // Fear skills cannot be used l2pcinstance to l2pcinstance. Heroic
  63. // Dread, Curse: Fear, Fear, Horror, Sword Symphony, Word of Fear and
  64. // Mass Curse Fear are the exceptions.
  65. if (getEffected() instanceof L2PcInstance
  66. && getEffector() instanceof L2PcInstance
  67. && getSkill().getId() != 1376 && getSkill().getId() != 1169
  68. && getSkill().getId() != 65 && getSkill().getId() != 1092
  69. && getSkill().getId() != 98 && getSkill().getId() != 1272
  70. && getSkill().getId() != 1381)
  71. return false;
  72. if (getEffected() instanceof L2NpcInstance
  73. || getEffected() instanceof L2DefenderInstance
  74. || getEffected() instanceof L2FortCommanderInstance
  75. || getEffected() instanceof L2SiegeFlagInstance
  76. || getEffected() instanceof L2SiegeSummonInstance)
  77. return false;
  78. if (!getEffected().isAfraid())
  79. {
  80. if (getEffected().getX() > getEffector().getX())
  81. _dX = 1;
  82. if (getEffected().getY() > getEffector().getY())
  83. _dY = 1;
  84. getEffected().startFear();
  85. onActionTime();
  86. return true;
  87. }
  88. return false;
  89. }
  90. /**
  91. *
  92. * @see com.l2jserver.gameserver.model.L2Effect#onExit()
  93. */
  94. @Override
  95. public void onExit()
  96. {
  97. getEffected().stopFear(this);
  98. }
  99. /**
  100. *
  101. * @see com.l2jserver.gameserver.model.L2Effect#onActionTime()
  102. */
  103. @Override
  104. public boolean onActionTime()
  105. {
  106. int posX = getEffected().getX();
  107. int posY = getEffected().getY();
  108. int posZ = getEffected().getZ();
  109. posX += _dX * FEAR_RANGE;
  110. posY += _dY * FEAR_RANGE;
  111. if (Config.GEODATA > 0)
  112. {
  113. Location destiny = GeoData.getInstance().moveCheck(getEffected().getX(), getEffected().getY(), getEffected().getZ(), posX, posY, posZ, getEffected().getInstanceId());
  114. posX = destiny.getX();
  115. posY = destiny.getY();
  116. }
  117. if (!(getEffected() instanceof L2PetInstance))
  118. getEffected().setRunning();
  119. getEffected().getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(posX, posY, posZ, 0));
  120. return true;
  121. }
  122. }